morganstanley / modern-cpp-kafka

A C++ API for Kafka clients (i.e. KafkaProducer, KafkaConsumer, AdminClient)
Apache License 2.0
331 stars 86 forks source link

DEBUG conflicts with commonly-defined macro #202

Closed jzakrzewski closed 1 year ago

jzakrzewski commented 1 year ago

This: https://github.com/morganstanley/modern-cpp-kafka/blob/71c6a9e9d80efda50d935186f15cd08f5939deee/include/kafka/ClientConfig.h#L77

causes:

: error: expected unqualified-id before numeric constant
kafka/ClientConfig.h:77:34: note: in expansion of macro ‘DEBUG’
77 | static const constexpr char *DEBUG = "debug";
kenneth-jia commented 1 year ago

While, even the macro (might be from windows?) is "comonly-defined", doesn't mean it's not guilty. 😅 A workaround would be usingundef before including the ClientConfig.h. E.g.

#ifdef DEBUG
#undef DEBUG
#endif

#include <kafka/ClientConfig.h>
...
jzakrzewski commented 1 year ago

It's not so easy - our project actually relies on this macro. This also why UPPERCASE_IDENTIFIERS should be reserved to macros only - there are just too many possible conflicts.

BTW: This is not the first time this has been reported. See: https://github.com/morganstanley/modern-cpp-kafka/issues/127

kenneth-jia commented 1 year ago

BTW: This is not the first time this has been reported. See: #127

OH, yes, it comes back to KafkaClient.h via the included headers, -- so anyway you can't get rid of the ClientConfig.h. Maybe we should just remove the DEBUG from kafka::clients::Config.