【问题标题】:Linking libstdc++ statically on Mac OS X在 Mac OS X 上静态链接 libstdc++
【发布时间】:2013-12-10 14:01:18
【问题描述】:

我想在 Mac OS X 10.8.4 上静态链接 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.

【问题讨论】:

    标签: static g++ libstdc++


    【解决方案1】:

    我不知道您拥有的 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++"

    在这个由 Homebrew 构建的 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 系统上测试过这些可执行文件,但如果它们由于任何原因不能工作,我会更新这篇文章。

    【讨论】:

    • 不适用于 Apple LLVM 版本 10.0.0 (clang-1000.10.44.2)。 clang: error: unsupported option '-static-libgcc'。删除时:clang: warning: argument unused during compilation: '-static-libstdc++'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-11
    • 1970-01-01
    • 2014-02-03
    • 2010-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多