我想将我的 C++ 源代码添加到相应的 elf
二进制文件中,并且我正在寻找执行此操作的最佳方法。 (我正在使用代码的多个版本,并不是每个版本都应该提交到 svn 中)。
我可以使用 bash 的 >>
运算符附加源代码而不破坏 elf
文件吗?
或者 objcopy --add-section 是一种方法吗?
顺便说一句,是否有更好的主意,只需从源代码文件中递归地 grep
查找所有 #include
行即可确定使用的所有源代码文件?
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?
发布评论
评论(2)
您可以通过在命令行上使用“-E”选项从大多数 C/C++ 编译器获取预处理器的输出,例如,
objcopy 是一个简单的选择,但我遇到了 ELF 资源编译器 今天,它可能对您有用。它允许您在 ELF 文件中嵌入任何您想要的内容,甚至会生成 C/C++ 代码以允许您添加它。因此,您甚至可以创建一个您的代码可以链接的库,该库可以直接从可执行文件打印出可执行文件的源代码。
这提出了另一个想法......而不是仅仅包含所有预处理的源代码,您可以让可执行文件提供一个选项来打印所使用的方程。
You can get the output of the preprocessor from most C/C++ compilers by using the "-E" option on the command line, e.g.,
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.
如果您使用 gcc,则可以使用 -M 标志来获取包含所有包含文件的列表的文件。它被写入到 -o 指定的文件中,如下所示:
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: