2010-05-13 71 views
5

我想用g ++在MacOSX上構建一個通用二進制文件。但是,它並不真正起作用。我試圖用這個簡單的僞代碼:MacOSX上的g ++不能用-arch ppc64

#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產生一些不同的錯誤,雖然表現相似。

回答

7

ppc64對Snow Leopard的支持下降了。如果您構建並鏈接到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。

+0

顯然,蘋果並不打算更新gcc手冊頁。 – WhirlWind 2010-05-13 23:30:05

+4

這不是一個真正的GCC問題。這就是MacOSX10.6.sdk中沒有ppc64,不是GCC不支持ppc64。 gcc * DOES *仍然支持ppc64。在10.6 sdk中,只有C++運行時支持ppc64。 – 2010-05-13 23:33:37

+0

很酷,謝謝!該命令有效。 10.4 SDK的外觀如何?因爲我無法讓它工作。 – Albert 2010-05-13 23:42:27