有没有办法存储clang编译时标志在输出二进制? [英] Is there a way to store clang compile-time flags in the output binary?
问题描述
使用clang时,是否有一种方法可以在输出二进制文件中存储编译时标志?
Is there a way to store the compile-time flags in the output binary when using clang?
例如,运行后:
clang -O3 -c main.c
结果 main.o
文件应该包含 -O3
。
gcc有 -frecord-gcc-switches
,但我无法找到一个对应的clang。
gcc has -frecord-gcc-switches
but I'm unable to find an equivalent for clang.
推荐答案
由于ecatmur已经暗示在评论中。此功能目前不支持,如 https://llvm.org/bugs/show_bug中所述.cgi?id = 16291 。
As ecatmur already has implied in the comments. This feature is currently not supported as documented in bug https://llvm.org/bugs/show_bug.cgi?id=16291 .
但是,作为一个解决方法,当功能不可用时,我建议让你的构建过程定义一个宏程序使用clang的 -D
参数。例如,假设您从bash脚本调用此脚本(适用于您使用的任何构建工具):
However as a work around while the feature is not available I would suggest having your build process define a macro inside the program using clang's -D
argument. For example assuming you are invoking this from a bash script (adjust to whatever build tool you use):
CLANG_ARGS='-O3 -c main.c'
clang $CLANG_ARGS -D CLANG_ARGS="\"${CLANG_ARGS}\""
然后在你的C或C ++程序中添加以下行:
Then in your C or C++ programs you add something along the lines of:
const char clangArgs[] = CLANG_ARGS;
然后您可以使用调试器或某些这样甚至可以添加一些代码来打印它您使用 -V
或 - 版本
切换调用您的程序。
Which you can then retrieve using a debugger or some such or even could add some code to print it from your program when invoked with the -V
or --version
switch.
这篇关于有没有办法存储clang编译时标志在输出二进制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!