A problem of defines and libraries

Started by
1 comment, last by ApochPiQ 12 years ago
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.
Advertisement
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:

#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(...)".
[TheUnbeliever]
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++

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

This topic is closed to new replies.

Advertisement