5

我无法使用 GCC 4.7 编译包含任何 OSX 核心库的 Objective C 文件,例如:

#import <Foundation/Foundation.h>

由此产生的错误总是会导致奇怪的 GCC 输出:

gcc -c -pipe -O2 -arch x86_64 -mmacosx-version-min=10.8 -Wall -W  -I/usr/local/Cellar/qt/4.8.4/mkspecs/macx-g++ -I../TerrainFluid -I../TerrainFluid/external -I../TerrainFluid -I. ../TerrainFluid/external/osx_bundle.mm -o osx_bundle.o

In file included from 

/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:123:0,
                 from ../TerrainFluid/external/osx_bundle.mm:24:
/System/Library/Frameworks/Foundation.framework/Headers/NSTask.h:69:24: error: expected unqualified-id before '^' token
/System/Library/Frameworks/Foundation.framework/Headers/NSTask.h:69:24: error: expected ')' before '^' token
In file included from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:159:0,
                 from ../TerrainFluid/external/osx_bundle.mm:24:
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:36:15: error: expected unqualified-id before '^' token
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:36:15: error: expected ')' before '^' token
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:37:39: error: expected type-specifier before 'NSUserScriptTaskCompletionHandler'
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:53:15: error: expected unqualified-id before '^' token
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:53:15: error: expected ')' before '^' token
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:54:70: error: expected type-specifier before 'NSUserUnixTaskCompletionHandler'
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:68:15: error: expected unqualified-id before '^' token
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:68:15: error: expected ')' before '^' token
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:69:82: error: expected type-specifier before 'NSUserAppleScriptTaskCompletionHandler'
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:86:15: error: expected unqualified-id before '^' token
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:86:15: error: expected ')' before '^' token
/System/Library/Frameworks/Foundation.framework/Headers/NSUserScriptTask.h:87:72: error: expected type-specifier before 'NSUserAutomatorTaskCompletionHandler'
In file included from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:160:0,
                 from ../TerrainFluid/external/osx_bundle.mm:24:
/System/Library/Frameworks/Foundation.framework/Headers/NSXPCConnection.h:46:11: error: expected unqualified-id before '^' token
/System/Library/Frameworks/Foundation.framework/Headers/NSXPCConnection.h:46:11: error: expected ')' before '^' token
/System/Library/Frameworks/Foundation.framework/Headers/NSXPCConnection.h:46:11: error: expected ';' before '^' token
/System/Library/Frameworks/Foundation.framework/Headers/NSXPCConnection.h:47:11: error: expected unqualified-id before '^' token
/System/Library/Frameworks/Foundation.framework/Headers/NSXPCConnection.h:47:11: error: expected ')' before '^' token
/System/Library/Frameworks/Foundation.framework/Headers/NSXPCConnection.h:47:11: error: expected ';' before '^' token
make: *** [osx_bundle.o] Error 1

解决这个问题的方法是我只对 Objective C 文件使用 Apple 编译器,对其余代码使用 g++ (4.7)。

gcc -> /usr/bin/llvm-gcc
g++ -> /usr/local/bin/g++-4.7

我会为所有代码使用 clang,但它还不支持 OpenMP,而且 gcc-4.2 不支持 C++11。

是我使用的示例文件(它是 Wildfire Games OSX 资源包加载器)。我在一篇博客文章中读到,Apple 引入了一个 GCC 阻止程序来停止使用 GCC 进行编译。

现在有没有办法用非 Apple GCC(如 GCC 4.7)编译代码?到目前为止,除了使用 Apple 编译器之外,我还没有找到有关此问题的文档。

4

1 回答 1

0

第一个错误显示了问题。

@property (copy) void (^terminationHandler)(NSTask *) NS_AVAILABLE(10_7, NA);

这是块扩展。主线 GCC 不实现对块的支持。

于 2013-10-16T16:19:25.910 回答