How to check if a macro exists in an object file in C?

For example, I define a macro:

#ifdef VERSION
 //.... do something
#endif

How can I check if VERSION exist in my object file or not? I tried to disassemble it with objdump, but found no actual value of my macro VERSION. VERSION is defined in Makefile.

Answers


Try compiling with -g3 option in gcc. It stores macro information too in the generated ELF file.

After this, if you've defined a macro MACRO_NAME just grep for it in the output executable or your object file. For example,

$ grep MACRO_NAME a.out # any object file will do instead of a.out
Binary file a.out matches

Or you can even try,

$ 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.

Need Your Help

C# generic constraint: Array of Structs

c# arrays generics value-type generic-constraints

I would like to create a generic constraint that contains the type to be an array of value types (structs), something like: