Error C3861 (identifier not found) when including protocol buffers

When I #include "myprotobuf.pb.h" in any of my classes, I get the following error: “error C3861: ‘check’: identifier not found” in myproject.generated.cpp. Looking through the includes for protobuf, the only reference I find to a check function is in stubs/type_traits.h

It may be worth noting that I had to modify stubs/common.h in order to get it to compile with UE4. I added #include "AllowWindowsPlatformTypes.h" and #include "HideWindowsPlatformTypes.h" at the beginning and end of the file, just inside the include guards.

Has anyone dealt with this before?

I managed to fix this. In the stubs/type_traits.h file in protocol buffers, there is a line with #undef check (source on GitHub). Apparently check is #defined on Mac. I commented out the #undef and renamed check to check_UnrealFix. Everything seems to work now (on Windows; I can’t speak to Mac).

Can you please describe in more detail how you solved it.

My obersation as a UE4 rookie: It depends on if you include an UE4 header. If not, everything is fine to use protobuf.

I did the try with and without redifintion at the end of the file without success:

Line 77:

#define check_UNREAL_FIX check // temp variable
#undef check

Line 365:

// fix for unreal engine at the bottom of stubs/type_traits.h
#define check check_UNREAL_FIX

The issue is that UE4 uses a macro called check (It’s in AssertionMacros.h), and protobuf uses check as the name of a function (in type_traits.h). This would be an error already, although it would probably be easier to spot if protobuf didn’t #undef it first. They #undef it because check is already #defined in Apple’s Carbon API.

Luckily, protobuf’s usage of check is quite small. Youll need to rename check to something unique (like check_UnrealFix) in the is_base_of` struct, starting on line 71:

template<typename B, typename D>
struct is_base_of {
  typedef char (&yes)[1];
  typedef char (&no)[2];

  // BEGIN GOOGLE LOCAL MODIFICATION -- check is a #define on Mac.
  // #undef check                                                            // COMMENT OUT
  // END GOOGLE LOCAL MODIFICATION

  static yes check(const B*);                                                // HERE
  static no check(const void*);                                              // HERE

  enum {
    value = sizeof(check(static_cast<const D*>(NULL))) == sizeof(yes),       // HERE
  };
};

Also, you shouldn’t #undef check at the bottom, because UE4 has probably already #defined it at the point where type_traits.h gets included, and you don’t want to wipe that out.

Encountered the same problem, managed to compile by redefining the macro found in AssertionMacros.h (thanks anthony.deschamps) immediately after any includes of protobuf.

As of right now, the macro is defined as:
#define check(expr) { if(!(expr)) { FDebug::LogAssertFailedMessage( #expr, _FILE_, _LINE_ ); DebugBreakAndPromptForRemote(); FDebug::AssertFailed( #expr, _FILE, _LINE_ ); CA_ASSUME(expr); } }