Question

I am using two lib jsoncpp and imap (lib c-client).

json cpp have write function . but in imap lib they have some macro #define write safe_write which is overriding some macro from jsoncpp . I am not able to use both library at same time. how can I avoid this conflict ?

Was it helpful?

Solution

Assuming you don't use write macro from imap:

#include "imap.h"
#undef write
#include "jsoncpp.h"

OTHER TIPS

The best way to proceed is to encapsulate the offending header (here imap) in a header that'll behave "better".

Note that this #define is actually a lazy man inline function. You need to identify all the declarations of safe_write and provide appropriate overloads, in the same namespaces.

// my_imap.h
#include "imap.h"
#undef write

inline void write(FILE* file, char* content, size_t size) {
  safe_write(file, content, size);
}

// ...

Then include my_imap.h instead of imap.h.

As long as you have access to the headers and you are using a lib or dll, you should be able to #undef it, so long as you don't use the macro.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top