views:

336

answers:

2

Hi,

I want to add my C++ source code to the corresponding elf binary file and I'm looking for the best way to do this. (I'm using several versions of my code and not every version should be committed into svn).

Can I just append the source code without destroying the elf file using bash's >> operator? Or is objcopy --add-section a way to do this?

By the way, is there a better idea that just grep'ing all #include lines recursively from the source code files to determine ALL source code files that are used?

Cheers,

Manuel

A: 

If you're using gcc you could use the -M flag to get a file with a list of all included files. It's written to the file specified with -o, like this:

gcc -M -c my_file.c -o list_of_included_files.txt
Puppe
+1  A: 

You can get the output of the preprocessor from most C/C++ compilers by using the "-E" option on the command line, e.g.,

g++ -E my_file.c -o my_file_preproc.c

objcopy is an easy bet, but I ran across the ELF resource compiler today, and it might be useful to you. It allows you to embed anything you want in an ELF file, and will even generate C/C++ code to allow you to extra it. Thus, you could even create a library that your code could link with that would print out the source for the executable straight from the executable.

Which brings up another idea...rather than just include all the preprocessed source code, you could have the executable offer an option to print out the equation(s) that are used.

Chris Cleeland