This Blog is to share our knowledge and expertise on Linux System Administration and VMware Administration

Tuesday, March 1, 2016

Running the gcc preprocessor in RHEL


In certain situations it is needed to have source code preprocessed by gcc without undergoing the full compilation process. For example, this might be necessary when embedded SQL is included in C or C++ programs and the preprocesssed file will be passed on to another tool which will convert the SQL in native source code.


Using the -E parameter with gcc or g++ will produce only the preprocessed source code:

$ gcc -E program.c -o program.preprocessed

The program.preprocessed file will contain the file preprocessed by gcc (Macros will be expanded and all include files will be resolved). This preprocessed

# 131 "/usr/include/bits/types.h" 3 4
# 1 "/usr/include/bits/typesizes.h" 1 3 4
# 132 "/usr/include/bits/types.h" 2 3 4

These lines are linemarkers that show from which include files specific

$ gcc -E -P program.c -o program.preprocessed

No comments:

Post a Comment