2013-12-10 119 views
2

我想在Mac OS X 10.8.4上靜態鏈接libstdC++,以便可以在其他系統中使用該二進制文件。在Mac OS X上靜態鏈接libstdC++

我發現了一些關於linux的討論。我想知道什麼會爲Mac OS X.

http://www.trilithium.com/johan/2005/06/static-libstdc/

說明我有以下的GCC。

i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00) 
Copyright (C) 2007 Free Software Foundation, Inc. 
This is free software; see the source for copying conditions. There is NO 
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 

回答

2

我不知道,如果你有GCC 4.2.1支持這種方法,但在這裏,對我來說在OS類似的情況X 10.9什麼工作:

  • 升級到最新Xcode中的命令行工具(我有5.0.1.0.1.1382131676)
  • 安裝Homebrew
  • brew tap versions
  • brew install gcc48
  • 然後配置/與建立自己的軟件:

    CC=gcc-4.8 CXX=g++-4.8 LDFLAGS="-static-libgcc -static-libstdc++"

靜態標誌是可利用的,我在這個GCC 4.8編譯通過自制軟件,並將得到的可執行文件看起來像:

$ otool -L seqdb-compress 
seqdb-compress: 
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5) 
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1) 

沒有libgcc或libstdC++動態庫。我還沒有在不同的OS X系統上測試這些可執行文件,但如果它們不能以任何理由工作,它會更新這篇文章。