This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: -x option for gcc
- From: John Love-Jensen <eljay at adobe dot com>
- To: Anitha Boyapati <anithab at sankhya dot com>, MSX to GCC <gcc-help at gcc dot gnu dot org>
- Date: Fri, 20 Oct 2006 06:57:53 -0500
- Subject: 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