静态链接libstdc ++使用clang [英] Static link libstdc++ using clang

查看:2494
本文介绍了静态链接libstdc ++使用clang的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用GCC,我可以在我的Ubuntu 15.04上使用以下命令构建程序:

When I use GCC, I can build program on my Ubuntu 15.04 using this:

-static-libgcc -static-libstdc++



<

And compiled binary can run on "stock" Ubuntu 14.04 without any external packages, only standard updates.

是否可以使用此静态链接到 clang 的库来构建?

Is there possibility do build with this static linking to library with clang?

最常见的答案:


  • 使用测试ubuntu rep( ppa:ubuntu-toolchain-r / test
  • 更新服务器

  • 在目标服务器上重新编译

  • 不使用GCC

  • using test ubuntu rep (ppa:ubuntu-toolchain-r/test)
  • update server
  • recompile on target server
  • don't use GCC

不适合我。

运行它在Ubuntu 14.04.3 LTS?

Just can I do this with clang for run it on Ubuntu 14.04.3 LTS?

推荐答案

clang与gcc兼容此事。基本上对于使用iostream的hello-world程序,确保 libstdc ++ 需求(实际的lib版本可能在不同发行版之间有所不同):

clang is compatible with gcc on this matter. Basically for hello-world program that uses iostream to ensure libstdc++ requirement (actual lib versions may vary between distributions):

$ clang++ test.cpp
$ ldd ./a.out
        linux-vdso.so.1 (0x00007ffec65c0000)
        libstdc++.so.6 => /usr/lib/gcc/x86_64-pc-linux-gnu/5.3.0/libstdc++.so.6 (0x00007ff937bb6000)
        libm.so.6 => /lib64/libm.so.6 (0x00007ff9378b6000)
        libgcc_s.so.1 => /usr/lib/gcc/x86_64-pc-linux-gnu/5.3.0/libgcc_s.so.1 (0x00007ff93769e000)
        libc.so.6 => /lib64/libc.so.6 (0x00007ff9372fe000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ff937f3e000)

这里是 libstdc ++ libgcc_s 的依赖关系。但如果您添加 -static-libgcc -static-libstdc ++

Here is a dependency for libstdc++ and libgcc_s. But if you add -static-libgcc -static-libstdc++:

$ clang++ test.cpp -static-libgcc -static-libstdc++
$ ldd ./a.out
        linux-vdso.so.1 (0x00007ffe5d678000)
        libm.so.6 => /lib64/libm.so.6 (0x00007fb8e4516000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fb8e4176000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fb8e4816000)

这仍然依赖 libc ,但这是一个不同的问题。

That still leaves dependency on libc, but that is a different question.

clang:warning:参数在编译期间未使用:'-static-libstdc ++'表示clang忽略此标志,因为标志在当前情况下无用。前两个例子是编译C代码(显然不依赖于libstdc ++),或者发布无需链接的编译命令( -c 标志)。由于 .o 文件不能保存有关静态或动态链接的信息,因此必须在链接阶段指定此标志(并且为避免警告,仅在链接阶段)。

clang: warning: argument unused during compilation: '-static-libstdc++' means clang ignored this flag, because flag is useless in current situation. First two examples that coming to mind is compiling C code (which obviously don't depend on libstdc++), or issuing compile-only command without linking (-c flag). Since .o file cannot hold information about static or dynamic linking, this flag have to be specified on linking phase (and, to avoid warning, only on linking phase).

这篇关于静态链接libstdc ++使用clang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆