g++在 Mac OS X 上 - CoreServices.h 错误

发布于 2024-11-02 01:42:19 字数 1142 浏览 5 评论 0原文

当我使用 g++ 编译以下代码时,

#include <CoreServices/CoreServices.h>
int main(int argc, char ** argv)
{
  return 0;
}

出现此错误。

bash-3.2$ g++ test.C
In file included from /System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:43:0,
                 from /System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/CarbonCore.h:20,
                 from /System/Library/Frameworks/CoreServices.framework/Frameworks/AE.framework/Headers/AE.h:20,
                 from /System/Library/Frameworks/CoreServices.framework/Headers/CoreServices.h:21,
                 from test.C:1:
/System/Library/Frameworks/CoreFoundation.framework/Headers/CFBundle.h:147:120: error: format string argument not a string type

有谁知道我能做些什么来让它发挥作用?我正在尝试使用 mach_absolute_timeAbsoluteToNanoseconds,它位于 CoreServices.h 中,例如 此处

g++ -v
gcc version 4.5.0 20100107 (experimental) (GCC)

When I compile the following code with g++

#include <CoreServices/CoreServices.h>
int main(int argc, char ** argv)
{
  return 0;
}

I get this error.

bash-3.2$ g++ test.C
In file included from /System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:43:0,
                 from /System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/CarbonCore.h:20,
                 from /System/Library/Frameworks/CoreServices.framework/Frameworks/AE.framework/Headers/AE.h:20,
                 from /System/Library/Frameworks/CoreServices.framework/Headers/CoreServices.h:21,
                 from test.C:1:
/System/Library/Frameworks/CoreFoundation.framework/Headers/CFBundle.h:147:120: error: format string argument not a string type

Does anyone know what I can do to get it to work? I am trying to use mach_absolute_time and AbsoluteToNanoseconds, which is in CoreServices.h, like here.

g++ -v
gcc version 4.5.0 20100107 (experimental) (GCC)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万劫不复 2024-11-09 01:42:19

看起来您正在尝试使用 Apple 的框架而不使用 Apple 的工具链 - 这可能行不通。您的示例程序在这里对我来说编译得很好,使用 Xcode(和 clang)附带的 gcc:

$ cat example.cpp 
#include <CoreServices/CoreServices.h>
int main(int argc, char ** argv)
{
  return 0;
}
$ make example
g++     example.cpp   -o example
$ rm example
$ CXX=clang make example
clang     example.cpp   -o example
$ 

It looks like you're trying to use Apple's frameworks without using Apple's toolchain - that's probably not going to work. Your example program compiles fine here for me, using the gcc that came with Xcode (and with clang):

$ cat example.cpp 
#include <CoreServices/CoreServices.h>
int main(int argc, char ** argv)
{
  return 0;
}
$ make example
g++     example.cpp   -o example
$ rm example
$ CXX=clang make example
clang     example.cpp   -o example
$ 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文