nakiya nakiya - 1 year ago 36
Linux Question

Can I squeeze my own program between the preprocessor and compiler?

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 :).


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