问题描述
我有一个c + + 11库() )。我想将它分发到centos6和ubuntu12.04 LTS。
I have a c++11 library ( https://github.com/matiu2/cdnalizer ). I want to distribute it on centos6 and ubuntu12.04 LTS.
它在Ubuntu 13.10和Gentoo上编译得很好。
It compiles happily on Ubuntu 13.10 and Gentoo.
我试着编译尽可能多的静态,但仍然取决于一个glibc centos没有:
I tried compiling with as much staticness as I could, but it still depends on a glibc that centos doesn't have:
matiu@matiu-laptop:~/projects/cdnalizer/build/src/apache$ readelf -d mod_cdnalizer.so | grep NEED
0x0000000000000001 (NEEDED) Shared library: [libapr-1.so.0]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000006ffffffe (VERNEED) 0xd520
0x000000006fffffff (VERNEEDNUM) 3
构建行:
/usr/bin/g++ -fPIC -I/usr/local/include -I/usr/include -I/usr/include/x86_64-linux-gnu -I/usr/include/x86_64-linux-gnu/c++/4.8 -Wall -Wextra -g -shared -Wl,-soname,mod_cdnalizer.so -o mod_cdnalizer.so CMakeFiles/mod_cdnalizer.dir/mod_cdnalizer.cpp.o CMakeFiles/mod_cdnalizer.dir/config.cpp.o CMakeFiles/mod_cdnalizer.dir/filter.cpp.o ../libbase.a -lapr-1
我试过在centos上编译gcc-4.8.2,但它生成的二进制文件有类似的glibc依赖:
I have tried compiling gcc-4.8.2 on centos, but the binaries it produces have similar glibc dependencies:
[root@matt src]# ./test_config
./test_config: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by ./test_config)
./test_config: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by ./test_config)
我听说你无法为共享库转义glibc依赖,因为c ++引发了excoptions,所以需要共享libstdc ++(但是我的lib不会抛出
I heard that you can't escape glibc dependencies for shared libraries because c++ throws excoptions and so needs the shared libstdc++ (but my lib doesn't throw exceptions across the library boundary).
我也听说你不能静态链接glibc,因为静态库没有使用-fPIC编译。
I also heard that you can't link in glibc statically because the static lib was not compiled with -fPIC.
我的主要问题是:
- 我在centos6上分发我的c ++ 11共享库?
我的子问题是:
- 我可以在ubuntu 13.10上编译一个c ++ 11共享库,并且在centos6(和更旧的ubuntus)上加载它吗?如何?
- 我可以在centos6上编译一个c ++ 11共享库,并在标准centos安装上运行吗?
(不要担心Apache2.2 vs 2.4依赖...这是容易的一点)
(Don't worry about Apache2.2 vs 2.4 dependency .. that's the easy bit)
推荐答案
如果你不能使用标准的CentOS 6 g ++ / glibc / libstdc ++编译代码,那么就不能在标准的CentOS 6安装上运行。
If you can't build your code with the standard CentOS 6 g++/glibc/libstdc++, then no, it's not going to run on standard CentOS 6 installs.
CentOS发行版用于长期支持(LTS)。关键bug得到固定的更新,但软件否则不会改变,通常。 。即使使用第三方存储库(例如EPEL),CentOS的可用软件也不是最新的。
The CentOS distro is for long term support (LTS). Critical bugs get fixed with updates, but software otherwise doesn't change, usually. This is a feature. Even with 3rd party repositories (e.g. EPEL), the available software for CentOS isn't really recent.
如果你可以使用g ++ 4.4工具链编译它,在这种情况下,您不能使用更高级的编译器。在Ubuntu的12.04 LTS软件包列表中快速搜索显示libstdc ++ 6-4.5-dbg使用的版本 libstdc ++。so.6
这将是向后不兼容,基于错误消息
If you can compile it using the g++ 4.4 toolchain, sure. In this case, you cannot use a more advanced compiler. A quick search on Ubuntu's 12.04 LTS package list shows libstdc++6-4.5-dbg using a version of libstdc++.so.6
which would be backward incompatible, based on error messages above.
As you've shown above, you'll have at least one updated dependency (libstdc++.so.6
) that you'll need to ship with your library, and install in some odd location, with it's attendant headaches (LD_LIBRARY_PATH
, what happens to any other C++ plugins, etc.). And update at some point.
有些企业用户会反对这样的东西,主要是因为它与现有的操作系统不能很好地连接。
Some enterprise users would object to something like this, mainly because it doesn't mesh well with the existing OS.
在依赖关系中静态链接(例如与下面的开发人员工具集)可以工作也。它也不是没有问题(更新依赖关系再次),但可能是你的代码在CentOS 6上工作的最好的机会。
Statically linking in dependencies (like in Ali's answer with the Developer Toolset below) could work also. It's also not without problems (updates to dependencies again), but might be the best chance for your code to work on CentOS 6.
我看到从评论到阿里的答案, (gcc 4.7.0)没有工作,这使得devtools 1.1会工作。所以看起来你在这种情况下需要 C ++ 11支持,直到gcc 4.8的级别。
I see from comments to Ali's answer, that devtools 1 (gcc 4.7.0) didn't work, making it unlikely that devtools 1.1 would work. So it seems you do need C++11 support up to the level of gcc 4.8 in this case.
这篇关于如何在centos6上分发c ++ 11共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!