Hello,
I’m doing analysis of code building and have the problem with getting options of build command . For example, a file test.c is built with command:
gcc -I<include_path> test.c -o test -lx -ly -lz
I would like to get all the options of this build command: include path, main file, loaded libraries, …
I tried with scan-build and Checker, but I can get only the AnalyzerOpts->FullCompilerInvocation (only options of Analyzer but not the compiling process).
Then I think a plugin of clang, which is executed in process of compiling, should work well. But I can’t find class to retrieve all the build command options.
Please let me know: Is it possible to get these informations of build command? If yes so which class should be called to get these informations.
Thank you very much!
clang -### -I<include_path> test.c -o test -lx -ly -lz
should print out all the (tool) invocations, in this case frontend and linker invocations, and their flags.
Same tricks can be used on gcc as well, though the output format is slightly different.
1 Like
Thank you for your answer! It works!
How can we get the invocations programmatically? Or we should read from the stdout and then manipulate the output text?
Is there any suggestion for this question? )
You could use compilation databases:
https://clang.llvm.org/docs/JSONCompilationDatabase.html
They are basically json files describing the build. In clang you can sneak in -MJ
.
For larger CMake projects, there is -DCMAKE_EXPORT_COMPILE_COMMANDS=On
.
1 Like
I’m not aware of any specific infrastructure that could help here. For frontend driver options (i.e. clang -cc1
), you could use the option marshalling infra, but:
The marshalling infrastructure is not intended for driver-only options.
HTH,
Andrzej
1 Like
Thank you very much for you answer! This is exactly what I need!