This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: -x option for gcc


Hi Anitha,

> I fail to understand the use of x option  if all it does is to
> interpret the file by means of given language.Can you please shed some
> more light on it.

The -x option is useful for compiling, not linking.

For example:
cat Foo.cpp | gcc -c -x c++ - -o Foo.o

Notice that the input is coming from stdin.  Here, I simply used cat, but it
could have been any kind of more sophisticated code generator.

Also notice that I use -c, because using -x with gcc does not turn gcc into
a C++ toolchain driver.

In my builds, I use -x a lot, because I do a lot of code massaging with
preprocessors such as sed and perl to do macro-magic more capable than the
capabilities of the C preprocessor.

I'd rather *NOT* have to do such machinations on the code, but I don't want
to switch from C++.  Java and DPL supports all the code twiddling I need
natively, without resorting to sed or perl magic.  Anyway, my situation is
just a case example.

Another situation to use -x is when the files have an unrecognized
extension, and you want to explicitly tell the toolchain driver (such as
gcc, or g++) what the language is for the source file.

g++ -c -x c++ MyFunnyFile-cpp.23 -o MyFunnyFile.o

I've only seen that kind of situation in two projects I've worked on.

HTH,
--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]