I\'m performing some source processing between C preprocessing and C compilation. At the moment I:
gcc -E file.c > preprocessed_file.c.The warnings about restrict are due to the fact that it is a keyword in C99. So, you have to pre-process and compile your code using the same standard.
The error about _main is because your file doesn't define main()? Doing the following should work:
gcc -c -std=c99 bar.c
and it will create bar.o. If your bar.c has a main() defined in it, maybe it is not called bar.c? For example, I created a bar.c with a valid main(), and did:
gcc -E -std=c99 bar.c >bar.E
gcc -std=c99 bar.E
and got:
Undefined symbols:
"_main", referenced from:
start in crt1.10.6.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
In that case, you need the -x c option:
gcc -x c -std=c99 bar.E
(Or, as Nikolai mentioned, you need to save the pre-processed file to bar.i.)
Looks like a typo in the GCC docs - try '-x cpp-output' instead.
gcc -E helloworld.c > cppout
gcc -x cpp-output cppout -o hw
./hw
Hello, world!
Save the file with the .i suffix after pre-processing. Gcc man page:
file.i
C source code which should not be preprocessed.
file.ii
C++ source code which should not be preprocessed.