In Xcode, I’ve created a “Cocoa application” project. One of its dependencies is a framework containing C++ code. I renamed AppDelegate.m to AppDelegate.mm and included the framework.
The project fails to compile. The problem is that the C++ header files in the framework are using some symbols that conflict with Objective-C or Cocoa.
- The C++ header files are defining functions called
verify()andcheck(), which conflict with /usr/include/AssertMacros.h in the MacOSX10.8 SDK. - The C++ header files contain a variable called
NO, which conflicts with the Objective-C macroNO.
A workaround would be to modify the C++ code in the framework to avoid these conflicts. But since it’s a large C++ project maintained by another organization, this would take time and would possibly break in future updates of the C++ project.
Is there some way just to tell Clang/Xcode to treat those C++ header files as C++ instead of Objective-C++?
Reading through the
/usr/include/AssertMacros.hthat comes with Mac OS 10.8, it looks like you could do:before including
AssertMacros.h, which will prevent it from defining macros calledverify()andcheck().Regarding
NO: you could use the preprocessor to rename that variable for you. For example:Depending on how the
NOvariable is used by the library, this might cause problems — if the header is declaring it asextern, then your Cocoa app will refer to it by the wrong name, and you’ll get an undefined symbol error. But as long as you’re not using that variable, and the library isn’t depending on your app to define that variable, then you should be fine.(And please file a bug report with the offending library, requesting that they rename their variable.)