# A problem of defines and libraries

This topic is 2144 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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(...)".

##### Share on other sites
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.

 Ninja'd++