当我尝试编译任何包含 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 的终端中编译。
最佳答案
如前所述here , Carbon 早已被弃用。但是,您可以尝试 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 .
关于c++ - Mac OSX Sierra CoreFoundation/CoreServices/CoreGraphics 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40345859/