user1424739
user1424739

Reputation: 13645

Linking libstdc++ statically on Mac OS X

I want to link libstdc++ statically on Mac OS X 10.8.4 so that the binary can be used in other systems.

I found some discussion for linux. I'm wondering what would the instructions for Mac OS X.

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

I have the following 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.

Upvotes: 3

Views: 8379

Answers (1)

mhowison
mhowison

Reputation: 660

I don't know if the gcc 4.2.1 that you have supports this method, but here's what worked for me in a similar situation on OS X 10.9:

  • upgrade to the latest Xcode command line tools (I have 5.0.1.0.1.1382131676)
  • install Homebrew
  • brew tap versions
  • brew install gcc48
  • then configure/build your software with:

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

The static flags were available for me in this gcc 4.8 build by Homebrew, and the resulting executables looked like:

$ 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)

with no libgcc or libstdc++ dynamic libs. I haven't yet tested these executables out on a different OS X system but will update this post if they don't work for any reason.

Upvotes: 2

Related Questions