• Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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 this post


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

Share this post


Link to post
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.


[edit] Ninja'd++

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement