views:

68

answers:

2

Is this a stupid question? Or can I specify g++ to use a program between the preprocessor and compiler?

Alternatively, I know that I can just run the preprocessor on a file (hence all the files). Then I am guessing there is a switch to run only the compiler. So I can manually invoke these two and put my program between. If so, how do I run compiler(and linker?) only?

I'd rather prefer the first method as our builder would probably not agree with me :).

+2  A: 

To run an alternative preprocessor, the man page suggests using -no-integrated-cpp and -B.

I have no experience with these, so I suggest you read the relevant parts in the man page.


Alternatively, you can run the compiler without invoking the preprocessor by telling g++ that the language is "preprocessed C++":

g++ -x c++-cpp-output

g++ will also recognize files with the suffix .ii as preprocessed C++, so the pipeline becomes:

source.cpp -> source.ii: g++ -o source.ii -E source.cpp
source.ii -> source.custom.ii: <custom step>
source.custom.ii -> source.o: g++ -o source.o -c source.custom.ii
source.o -> source: g++ -o source source.o
Magnus Hoff
A: 

Look at the -Xpreprocessor option, this allows you to define new pre-processor interpretations

slashmais