Is there a way to store clang compile-time flags in the output binary?

后端 未结 1 1774

Is there a way to store the compile-time flags in the output binary when using clang?

For example after running:

clang -O3 -c main.c

The re

相关标签:
1条回答
  • 2021-02-19 12:47

    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 .

    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}\""
    

    Then in your C or C++ programs you add something along the lines of:

    const char clangArgs[] = CLANG_ARGS;
    

    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.

    0 讨论(0)
提交回复
热议问题