当我尝试编译包括CoreFoundation,CoreServices或CoreGraphics在内的任何内容时,例如Carbon,我收到以下错误消息。
gcc x.c -framework Carbon
In file included from /usr/include/Availability.h:180:0,
from /usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin16.1.0/6.2.0/include-fixed/math.h:46,
from /System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:24,
from /System/Library/Frameworks/CoreServices.framework/Headers/CoreServices.h:19,
from /System/Library/Frameworks/Carbon.framework/Headers/Carbon.h:20,
from x.c:1:
/System/Library/Frameworks/CoreFoundation.framework/Headers/CFDateFormatter.h:53:34: error: 'introduced' undeclared here (not in a function)
kCFISO8601DateFormatWithYear API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0)) = (1UL << 0),
^
/System/Library/Frameworks/CoreFoundation.framework/Headers/CFURL.h:777:39: error: 'deprecated' undeclared here (not in a function)
const CFStringRef kCFURLLabelColorKey API_DEPRECATED("Use NSURLLabelColorKey", macosx(10.6, 10.12), ios(4.0, 10.0), watchos(2.0, 3.0), tvos(9.0, 10.0));
^
/System/Library/Frameworks/CoreFoundation.framework/Headers/CFURL.h:777:39: error: 'message' undeclared here (not in a function)
const CFStringRef kCFURLLabelColorKey API_DEPRECATED("Use NSURLLabelColorKey", macosx(10.6, 10.12), ios(4.0, 10.0), watchos(2.0, 3.0), tvos(9.0, 10.0));
^
In file included from /System/Library/Frameworks/Security.framework/Headers/Security.h:81:0,
from /System/Library/Frameworks/CoreServices.framework/Frameworks/OSServices.framework/Headers/CSIdentity.h:43,
from /System/Library/Frameworks/CoreServices.framework/Frameworks/OSServices.framework/Headers/OSServices.h:27,
from /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Headers/IconsCore.h:23,
from /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Headers/LaunchServices.h:22,
from /System/Library/Frameworks/CoreServices.framework/Headers/CoreServices.h:39,
from /System/Library/Frameworks/Carbon.framework/Headers/Carbon.h:20,
from x.c:1:
/System/Library/Frameworks/Security.framework/Headers/Authorization.h:194:7: error: variably modified 'bytes' at file scope
char bytes[kAuthorizationExternalFormLength];
^~~~~
In file included from /System/Library/Frameworks/CoreGraphics.framework/Headers/CGContext.h:18:0,
from /System/Library/Frameworks/CoreGraphics.framework/Headers/CGBitmapContext.h:9,
from /System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h:11,
from /System/Library/Frameworks/ApplicationServices.framework/Headers/ApplicationServices.h:35,
from /System/Library/Frameworks/Carbon.framework/Headers/Carbon.h:24,
from x.c:1:
/System/Library/Frameworks/CoreGraphics.framework/Headers/CGFont.h:53:40: error: initializer element is not constant
static const CGFontIndex kCGGlyphMax = kCGFontIndexMax;
有谁知道问题可能是什么?我不确定在更新到macOS Sierra或Xcode到8.1之后是否已经开始。编辑:该程序似乎在Xcode中编译,但不在使用自制程序gcc 6.2的终端中编译。
答案 0 :(得分:1)
如前所述,here,碳已被弃用。但是,您可以尝试使用AppKit:
gcc x.c -framework AppKit
对我而言,当我为OS X编写纯C应用程序时,它可以正常工作。
[编辑:]现在代码。
#include <ApplicationServices/ApplicationServices.h>
#include <unistd.h>
int main() {
while (!CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, 0x7E))
usleep(10000);
return 0;
}
此应用程序仅依赖于AppKit和循环,直到按下向上箭头(扫描代码0x7E
)。
这里是完整的代码列表(不确定它们在官方标题中的位置):Carbon's Virtual Key Codes。
答案 1 :(得分:1)
/System/Library/Frameworks/CoreFoundation.framework/Headers/CFDateFormatter.h:53:34: error: 'introduced' undeclared here (not in a function)
kCFISO8601DateFormatWithYear API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0)) = (1UL << 0),
恕我直言,这只是gcc-6.2不支持这个标题,而只是clang。也许它会用gcc-7“修复”。
gcc-5.x和El Capitan(sdk 10.11)存在类似的问题,其中需要gcc-6.x才能使用像这样的Apple标头进行构建。
答案 2 :(得分:0)
您使用&#34; Core-Foundation&#34;标记了这一点。但是您正在谈论的可用性宏(在Foundation Release Notes for macOS 10.12 & iOS 10的前几段中有更详细的描述会更详细地描述API可用性宏。
我怀疑你可能只需要在你的构建中包含Foundation框架(以获取CoreFoundation和CoreGraphics似乎依赖的这些宏),你应该可以继续。