5

我正在尝试使用 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 上。我已经安装了带有所有 SDK 的 Xcode 3.2.2。GCC 4.2 是默认的。GCC 4.0 会产生一些不同的错误,但行为相似。

4

1 回答 1

7

在雪豹中删除了 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。

于 2010-05-13T23:26:24.870 回答