I'm trying to build protobuf c++ into ios. But its implementation contains a TYPE_BOOL enum variable that conflicts with TYPE_BOOL in ios macro. And compile failed.
How to solve this?
I'm trying to build protobuf c++ into ios. But its implementation contains a TYPE_BOOL enum variable that conflicts with TYPE_BOOL in ios macro. And compile failed.
How to solve this?
There are a few reasonable (but hacky) options:
#include
any protobuf headers that use TYPE_BOOL
before you #include
any iOS headers. Example:
#include <google/protobuf/descriptor.h>
#include <ConditionalMacros.h>
This lets you use iOS's TYPE_BOOL
in your own code, but not protobuf's TYPE_BOOL
.
#include
the iOS header, then #undef TYPE_BOOL
before you #include
the protobuf header. Example:
#include <ConditionalMacros.h>
#undef TYPE_BOOL
#include <google/protobuf/descriptor.h>
This lets you use protobuf's TYPE_BOOL
in your own code, but not iOS's TYPE_BOOL
.
If you need both definitions, this might work (not tested):
#include <google/protobuf/descriptor.h>
// Make a copy of TYPE_BOOL before it is hidden by a macro.
const google::protobuf::FieldDescriptor::Type PROTOBUF_TYPE_BOOL =
google::protobuf::FieldDescriptor::TYPE_BOOL;
#include <ConditionalMacros.h>
Now use PROTOBUF_TYPE_BOOL
when you need the Protobuf definitions.
Note that google/protobuf/descriptor.pb.h
also defines a TYPE_BOOL
. It can be solved in the same way, but most people don't use that header, so I left it out of the examples.