Tech Journal Back to Tech Journal

How can I use gcc as a preprocessor?

Using the gcc program as a preprocessor (for macros, etc.) can be really convenient if you are used to using C-style preprocessor directives. Otherwise, you might be better served by using m4 (which is what the gcc preprocessor is based on, anyway.)

To use gcc, use:

$ gcc -P -E -x c -C <inputfile> -o<outputfile>

-E is just to process, not compile. -P is so the output doesn't contain #line directives. -x c tells the interpreter to treat the file like a C-source file, no matter what it thinks. -C prevents it from discarding comments.

Last updated on 2005-08-24 14:00:00 -0700, by Shalom Craimer

Back to Tech Journal