I have two libraries and unfortunately they define two identical preprocessor definitions (which I need to use):
lib1.h
#define MYINT 1
lib2.h
#define MYINT 2
In my program I need to use both of them:
#include <Lib1.h>
#include <lib2.h>
...
int myint = MYINT;
And here I have error that MYINT can't be resolved.
How can I solve that when I cannot modify the lib files?
You might #undef MYINT
before to include the header as workaround.
#undef MYINT
#include <Lib1.h>
const int myint_lib1 = MYINT; // 1
#undef MYINT
#include <lib2.h>
const int myint_lib2 = MYINT; // 2
Get the MYINT
value of the first library before the second one replaces it.
#include <Lib1.h>
int myInt1 = MYINT;
#undef MYINT
#include <lib2.h>
int myInt2 = MYINT;
#undef MYINT
Of course, that doesn't work if MYINT
is something dynamic and you need to keep its actual content around.
Edited by handy999: no semicolon at the end of preprocessor statements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With