如何检查C中的目标文件中是否存在宏?

Amu*_*umu 1 c object-files

例如,我定义了一个宏:

#ifdef VERSION
 //.... do something
#endif
Run Code Online (Sandbox Code Playgroud)

如何检查VERSION目标文件中是否存在?我试着用它拆解它objdump,但发现我的宏没有实际价值VERSION.VERSION在Makefile中定义.

Pav*_*ath 6

尝试使用-g3选项进行编译gcc.它还在生成的ELF文件中存储宏信息.

在此之后,如果你定义一个宏MACRO_NAME只是grep它在输出可执行文件或目标文件.例如,

$ grep MACRO_NAME a.out # any object file will do instead of a.out
Binary file a.out matches
Run Code Online (Sandbox Code Playgroud)

或者你甚至可以尝试,

$ strings -a -n 1 a.out | grep MACRO_NAME

 -a Do not scan only the initialized and loaded sections of object files; 
    scan the whole files.

 -n min-len Print sequences of characters that are at least min-len characters long,
    instead of the default 4.
Run Code Online (Sandbox Code Playgroud)