Supposing I have Library A, which contains some debug code that depends on #defines to run, and Project B, which references Library A.
How do I set the defines in Project B, such that Library A "sees" them?
Thanks.
A problem of defines and libraries
You don't, unless library A is header-only (in which case you just set a project-wide definition). #define is a preprocessor macro - compiled code (as in a .lib, say) never sees the processor again. Perhaps you could have two functions, with and without debugging code and then use something like this in the header:
or perhaps you could just make it something set at runtime. At least some libraries I've used have had something like "setDebugLevel(...)".
#ifdef LIBA_NOISY
#define confabulate confabulate_noisy
#else
#define confabulate confabulate_quiet
#endif
or perhaps you could just make it something set at runtime. At least some libraries I've used have had something like "setDebugLevel(...)".
You don't.
Libraries are link-time entities. #defines are pre-processor entities. They exist only before compilation even starts in earnest, and are long gone by the time you reach library status.
The closest you can come is a hack: use a shared header file that both Library A and B include at compile time, with the #defines in it. And pray you don't go out of sync.
[edit] Ninja'd++
Libraries are link-time entities. #defines are pre-processor entities. They exist only before compilation even starts in earnest, and are long gone by the time you reach library status.
The closest you can come is a hack: use a shared header file that both Library A and B include at compile time, with the #defines in it. And pray you don't go out of sync.
[edit] Ninja'd++
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement