Issue
How i could save le preprocessor in output file with specific name as x or y ?
I tried the command line :
gcc -E -o pgcd.c x.o
But it don't seem being the solution.
ps: the file doesn't exist before the compilation, i just would save the preprocessor in a file with the name i defined.
Thank you for any help.
Solution
gcc -E file.c
will preprocess file.c
and write the preprocessed source code to the
standard output (console). So to save the preprocessed output, redirect
the standard output to a file of your choice:
gcc -E file.c > somefile
It is a bad idea for somefile to have an .o
extension. GCC and other
tools interpret the .o
extension as meaning that the file contains object
code, as output by compilation. Preprocessing file.c
does not produce
object code. It just produces preprocessed source code, which you might later compile.
The conventional file extension for preprocessed C source code is .i
(.ii
for preprocessed C++ source code). Therefore
gcc -E file.c > file.i
is the appropriate choice.
You will discover that file.i
contains preprocessor line-markers, e.g.
# 1 "file.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "file.c"
# 1 "/usr/include/stdio.h" 1 3 4
# 27 "/usr/include/stdio.h" 3 4
...
...
If you don't want these line-markers to appear in the output, add the -P
option:
gcc -E -P file.c > file.i
Answered By - Mike Kinghan