-x option for gcc
John Love-Jensen
eljay@adobe.com
Fri Oct 20 11:58:00 GMT 2006
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
More information about the Gcc-help
mailing list