How can I create a macro for getting the library name a class is compiled into? Is there some way of getting this information from make?
Essentially I’d like to do something like:
# define LIBRARY_NAME (get info from make maybe?)
...
# ifdef LIBRARY_NAME
static const char* s_lib_name = STRINGIZE(LIBRARY_NAME);
Thank you!
g++allows you to use-DMACRO_NAME=MACRO_VALUEto supply macro values on the command line. Presumably other compilers have similar features.This is equivalent to having
at the top of each file being processed.
Leaving out the
=MACRO_VALUEpart is equivalent to a plain#define MACRO_NAME.So now all you have to do is get
maketo keep track of the final destination for each file you’re compiling (which may or may not be trivial, depends on exactly what you’re doing…).You might also look into the
#stringization and##tokenization operators in the c preprocessor. They could save you a little work here…