c++ - 带有 mmacosx-version-min 和 Foundation header 的 MacPorts GCC 4.8.2 错误

标签 c++ gcc macports foundation

我正在运行 10.9.2 并通过 MacPorts (sudo port install gcc48 +universal) 安装了 GCC 4.8.2 并且无法编译设置 -mmacosx-version- 的 Objective-C 代码min=10.8 或任何其他版本,包括 Foundation。如果我将版本设置为 10.9 或者根本不设置它,它就可以工作。

代码如下:

#include <Foundation/Foundation.h>
int main() {
    return 0;
}

命令如下:

g++-mp-4.8 objctest.m -mmacosx-version-min=10.8 -framework Foundation

我收到的错误是:

In file included from /usr/include/Availability.h:148:0,
             from /opt/local/lib/gcc48/gcc/x86_64-apple-darwin13/4.8.2/include-fixed/math.h:46,
             from /System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:19,
             from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:6,
             from objctest.m:1:
/System/Library/Frameworks/Foundation.framework/Headers/NSUserNotification.h:16:45: error: expected ',' or '}' before '__attribute__'
 NSUserNotificationActivationTypeReplied NS_AVAILABLE(10_9, NA) = 3
                                         ^

即使我像这样添加 -isysroot 参数:

-isysroot `xcodebuild -version -sdk macosx Path` 

它仍然不起作用(尽管它给出了与 SDK 相关的错误)。

是 MacPorts GCC 有问题还是 GCC 和 OS X header 有问题?

我的最终目标是为 10.6 编译一个使用 C++11 特性的完整程序 (Qt gui),因此 GCC 是必须的,因为 10.6 没有 libc++。

更新 1:OS X 的 header 将 __attribute__((weak_import)) 应用于单个枚举类型,而 GCC 显然不支持这一点:

For an enum, struct or union type, you may specify attributes either between the enum, struct or union tag and the name of the type, or just past the closing curly brace of the definition.

我不想修补 SDK header ,所以看起来这是不行的。

更新 2:这是一个记录在案的 Clang 扩展:

Clang allows attributes to be written on individual enumerators. This allows enumerators to be deprecated, made unavailable, etc. The attribute must appear after the enumerator name and before any initializer

最佳答案

您在尝试将框架头文件与 gcc-4.8 一起使用时遇到了问题。它提示的是枚举器上存在属性,例如

enum foo {
   foo_alice = 1,
   foo_bob = 2,
   foo_carol __attribute__((deprecated)) = 3
};

但是 gcc 不支持这个;这是a clang extension .通常 gcc 会修改 header 以使它们工作,但它只会影响系统 header 而不影响框架 header 。

我只是想知道当 QtC++ 时为什么你要尝试编译 Objective-C 代码,而且,我会希望,不依赖于 Objective-C 功能。

关于c++ - 带有 mmacosx-version-min 和 Foundation header 的 MacPorts GCC 4.8.2 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22519756/

相关文章:

linux - 如何在 CentOS 上安装 gcc 4.7.3?

c - 为什么 SP(显然)存储在 Cortex-M3 的异常条目上?

.net - 用于安装 DotNet 的 MacPorts OpenSSL 强制链接

opencv - 在 Macports 中安装支持 Cuda 的 OpenCV?

c++ - "long"和 "long int"之间的区别,abs & labs

c++ - 使用反射在 protobuf 消息中设置 oneof

android - android上的Qt,减少二进制大小

c++ - 驱动器号重复

c - 如何强制正在运行的程序使用外部方式将其 I/O 缓冲区的内容刷新到磁盘?

ruby - MacPorts 如何安装软件包?如何激活通过 MacPorts 完成的 Ruby 安装?