我正在尝试使用 g++ 在 MacOSX 上构建通用二进制文件。然而,它并没有真正起作用。我尝试过这个简单的虚拟代码:
#include <iostream>
using namespace std;
int main() {
cout << "Hello" << endl;
}
这工作正常:
% g++ test.cpp -arch i386 -arch ppc -arch x86_64 -o test
% file test
test: Mach-O universal binary with 3 architectures
test (for architecture i386): Mach-O executable i386
test (for architecture ppc7400): Mach-O executable ppc
test (for architecture x86_64): Mach-O 64-bit executable x86_64
然而,这并不:
% g++ test.cpp -arch i386 -arch ppc -arch x86_64 -arch ppc64 -o test
In file included from test.cpp:1:
/usr/include/c++/4.2.1/iostream:44:28: error: bits/c++config.h: No such file or directory
In file included from /usr/include/c++/4.2.1/ios:43,
from /usr/include/c++/4.2.1/ostream:45,
from /usr/include/c++/4.2.1/iostream:45,
from test.cpp:1:
/usr/include/c++/4.2.1/iosfwd:45:29: error: bits/c++locale.h: No such file or directory
/usr/include/c++/4.2.1/iosfwd:46:25: error: bits/c++io.h: No such file or directory
In file included from /usr/include/c++/4.2.1/bits/ios_base.h:45,
from /usr/include/c++/4.2.1/ios:48,
from /usr/include/c++/4.2.1/ostream:45,
from /usr/include/c++/4.2.1/iostream:45,
from test.cpp:1:
/usr/include/c++/4.2.1/ext/atomicity.h:39:23: error: bits/gthr.h: No such file or directory
/usr/include/c++/4.2.1/ext/atomicity.h:40:30: error: bits/atomic_word.h: No such file or directory
...
知道为什么吗?
我使用的是 MacOSX 10.6。我已经安装了 Xcode 3.2.2 及其附带的所有 SDK。 GCC 4.2 是默认值。 GCC 4.0 产生一些不同的错误,但行为相似。
Snow Leopard 中放弃了 ppc64 支持。如果您针对 Mac OS X 10.5 SDK 进行构建和链接,您仍然可以使用 ppc64。
在命令行尝试以下命令:
g++ test.cpp -arch i386 -arch ppc -arch x86_64 -arch ppc64 -mmacosx-version-min=10.5 -isysroot/Developer/SDKs/MacOSX10.5.sdk -DMACOSX_DEPLOYMENT_TARGET=10.5 -o test
或者对于 10.4 SDK 使用:
g++-4.0 test.cpp -arch i386 -arch ppc -arch x86_64 -arch ppc64 -mmacosx-version-min=10.4 -isysroot/Developer/SDKs/MacOSX10.4u.sdk -DMACOSX_DEPLOYMENT_TARGET=10.4 -o test
请注意,如果您想使用 10.4 SDK,则必须使用 gcc 4.0 (或 g++4.0 )。 Apple 的 GCC 4.2 不支持 10.4 SDK。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)