Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating one C file when compiling multiple sources

Tags:

c

gcc

I have a set of C files to compile using gcc and make. The build process works fine. I want to know if I can obtain - during compilation - one C file containing all the source code without any preprocessor macro.

like image 845
Abdelraouf Ouadjaout Avatar asked Mar 14 '26 02:03

Abdelraouf Ouadjaout


2 Answers

One simple was would be to make a file that included all the other source files.

$cat *.c > metafile.c

This would construct such a file, depending on how you set you 'pragma once' and ifndef's this file would probably not be able to compile on its own.

On the other hand, if what you want in a file where all the preprocessor macro's have been unfolded and evaluated, then the answer is to add the following to gcc:

-save-temps

then the file .ii will contain the unfolded and evaluated macros

like image 60
Martin Kristiansen Avatar answered Mar 16 '26 16:03

Martin Kristiansen


If you include all files to the gcc compiler at once you could use

gcc -E main.c other.c another.c

This will also include the stdlib functions maybe use -nostdinc

like image 33
DipSwitch Avatar answered Mar 16 '26 16:03

DipSwitch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!