Re: -x option for gcc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux