osx - 如何从 Objective C++ 中使用Boost图库?

  显示原文与译文双语对照的内容

试着从Objective-C++中找出BGL的用法。 有什么错误。重现步骤:

  1. 新建 Cocoa 应用程序项目。
  2. 将 MyAppDelegate.m 重命名为 MyAppDelegate.mm
  3. 添加 #include <boost/shared_ptr.hpp> to MyAppDelegate.mm 。( 假设你已经设置了标题搜索路径。)
  4. 添加 #include <boost/graph/adjacency_list.hpp> 到 MyAppDelegate.mm

boost/graph/adjacency_list.hpp 包含的某些传递的东西与一些旧碳头被 Cocoa 头导入的旧碳头碰撞。 下面是我看到( 。错误的第一个值)的输出:


In file included from/Users/me/Documents/Projects/BoostTest/BoostTest/MyAppDelegate.mm:10:
In file included from/Users/me/Documents/Projects/BoostTest/boost/graph/adjacency_list.hpp:33:
In file included from/Users/me/Documents/Projects/BoostTest/boost/graph/graph_traits.hpp:27:
In file included from/Users/me/Documents/Projects/BoostTest/boost/pending/property.hpp:13:
In file included from/Users/me/Documents/Projects/BoostTest/boost/type_traits.hpp:35:
In file included from/Users/me/Documents/Projects/BoostTest/boost/type_traits/has_operator.hpp:12:
In file included from/Users/me/Documents/Projects/BoostTest/boost/type_traits/has_bit_and.hpp:43:
/Users/me/Documents/Projects/BoostTest/boost/type_traits/detail/has_binary_operator.hpp:154:42: error: expected member name or ';' after declaration specifiers
 static ::boost::type_traits::yes_type check(has_operator);//this version is preferred when operator exists
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
In file included from/Users/me/Documents/Projects/BoostTest/BoostTest/MyAppDelegate.mm:9:
In file included from/Users/me/Documents/Projects/BoostTest/BoostTest/MyAppDelegate.h:9:
In file included from/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h:12:
In file included from/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:76:
In file included from/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSURLError.h:12:
In file included from/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/CoreServices.framework/Headers/CoreServices.h:23:
In file included from/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/AE.framework/Headers/AE.h:20:
In file included from/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/CarbonCore.h:115:
In file included from/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/Debugging.h:212:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/AssertMacros.h:1291:28: note: expanded from macro 'check'
 #define check(assertion) __Check(assertion)
 ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/AssertMacros.h:280:5: note: expanded from macro '__Check'
 do 
 ^

如果将 #import <Cocoa/Cocoa.h> 从项目头的前缀中移除,则 #include <boost/graph/adjacency_list.hpp> 在 MyAppDelegate.mm 中包括 <Cocoa/Cocoa.h> 之前,它将编译,但这是子优化/不需要的。

有什么简单的方法可以做( 理想的前缀头,所以我不需要在任何地方做这个),让 Cocoa 头和to标头共同存在?

时间: 作者:

我应该在asking的时候再搜索 。 发布这个帖子后,我发现了 ,这说明在包含标头之前添加下面的行将会产生以下的技巧:


#define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0

我试图在我的个人 MyAppDelegate.mm 文件中进行这项操作,但它没有工作,但是这是因为前缀头。 将它添加到项目头的前缀之前,它包含了 Cocoa/Cocoa.h

作者:
...