使用现代编译器编译的C ++项目,但与过时的libstdc ++链接 [英] C++ project compiled with modern compiler, but linked against outdated libstdc++

查看:130
本文介绍了使用现代编译器编译的C ++项目,但与过时的libstdc ++链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑在 Centos 7 虚拟机或容器中构建并交付C ++项目的情况。 Centos 7 的默认 gcc 4.8 。为了允许开发人员使用现代C ++,已安装了最新版本的 gcc (例如, 6.3 )进入作为CI服务器运行的Centos 7。这提供了 -std = c ++ 14 的支持。

Consider the situation when a C++ project is built and shipped within a Centos 7 virtual machine or container. Default gcc for Centos 7 is 4.8. In order to allow developers to use modern C++, the more recent version of gcc (for example, 6.3) is installed into Centos 7 which runs as a CI server. This provides -std=c++14 support.

[builder@f7279ae9f33f build (master %)]$ /usr/bin/c++ -v 2>&1 | grep version
gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) 
[builder@f7279ae9f33f build (master %)]$ /opt/rh/devtoolset-6/root/usr/bin/c++  -v 2>&1 | grep version
gcc version 6.3.1 20170216 (Red Hat 6.3.1-3) (GCC) 
export CXX=/opt/rh/devtoolset-6/root/usr/bin/c++
make all -j4
...

这是编译和链接命令的简短示例:

This is short example of compilation and linkage command:

[ 78%] Building CXX object CMakeFiles/ucsdos.dir/src/merge_operator_string.cpp.o
/opt/rh/devtoolset-6/root/usr/bin/c++  -Ducsdos_EXPORTS -I/home/builder/src/dos/libucsdos/./src -I/home/builder/src/dos/libucsdos/./include -I/home/builder/src/dos/libucsdos/build/schema/cpp -I/home/builder/src/dos/libucsdos/build/schema -isystem /usr/local/include  -O2 -g -DNDEBUG -fPIC   -frtti -pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Wundef -Werror -Wno-unused -std=gnu++14 -o CMakeFiles/ucsdos.dir/src/merge_operator_string.cpp.o -c /home/builder/src/dos/libucsdos/src/merge_operator_string.cpp

[ 80%] Linking CXX shared library libucsdos.so
/usr/bin/cmake3 -E cmake_link_script CMakeFiles/ucsdos.dir/link.txt --verbose=1
/opt/rh/devtoolset-6/root/usr/bin/c++ -fPIC -O2 -g -DNDEBUG  -shared -Wl,-soname,libucsdos.so.0 -o libucsdos.so.0.3.23 CMakeFiles/ucsdos.dir/src/c.cpp.o CMakeFiles/ucsdos.dir/src/crdt_2p_set.cpp.o CMakeFiles/ucsdos.dir/src/crdt_pn_counter.cpp.o CMakeFiles/ucsdos.dir/src/errors.cpp.o CMakeFiles/ucsdos.dir/src/merge_index_document.cpp.o CMakeFiles/ucsdos.dir/src/merge_index_segment.cpp.o CMakeFiles/ucsdos.dir/src/merge_operator_string.cpp.o -Wl,-rpath,/usr/local/lib: schema/libschema.a /usr/lib64/librocksdb.so /usr/lib64/libjemalloc.so /usr/local/lib/libgrpc++_reflection.so /usr/local/lib/libgrpc++.so /usr/local/lib/libgrpc.so -ldl -lgrpc++ /usr/lib64/libprotobuf.so -lpthread /usr/lib64/libprotobuf-lite.so 

无论如何,生成的工件似乎与 libstdc ++

Anyway, the resulting artifacts appear to be linked with system default version of libstdc++:

[builder@f7279ae9f33f build (master %)]$ ldd libucsdos.so | grep libstdc++.so.6
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f2a4a054000)

很容易发现 / lib64 / libstdc ++。so.6 版本是 4.8.5

[builder@f7279ae9f33f build (master %)]$ yum whatprovides "/lib64/libstdc++.so.6"
libstdc++-4.8.5-28.el7_5.1.x86_64 : GNU Standard C++ Library
Repo        : @Updates
Matched from:
Filename    : /lib64/libstdc++.so.6

此构建环境配置有效吗?

Is this build environment configuration valid?

推荐答案


无论如何,生成的工件似乎与libstdc ++的系统默认版本相关联:

Anyway, the resulting artifacts appear to be linked with system default version of libstdc++:

是。 devtoolset-6-gcc-c ++ 软件包提供了GCC的自定义版本,该版本使用特殊的链接描述文件而不是 libstdc ++。so的动态库。 / code>。这意味着它生成的二进制文件不依赖于更新的 libstdc ++。so.6 ,并且可以在未安装devtoolset的其他CentOS计算机上运行(即,它们仅具有

Yes. The devtoolset-6-gcc-c++ package provides a custom version of GCC that uses a special linker script instead of a dynamic library for libstdc++.so. That means the binaries it produces do not depend on the newer libstdc++.so.6 and can be run on other CentOS machines that don't have devtoolset installed (i.e. they only have the older libstdc++ library from GCC 4.8).


此构建环境配置有效吗?

Is this build environment configuration valid?

是。您所看到的是完全正常的,以及它应该如何工作。

Yes. What you're seeing is completely normal, and how it's supposed to work.

来自GCC 6.4.0的较新C ++运行时的片段静态链接到您的二进制文件中,而在运行时,它仅取决于每个CentOS系统都已安装的旧 libstdc ++。so

The pieces of the newer C++ runtime from GCC 6.4.0 get statically linked into your binary, and at runtime it only depends on the old libstdc++.so which every CentOS system has installed.

这就是全部GCC的devtoolset版本的点。

That's the whole point of the devtoolset version of GCC.

这篇关于使用现代编译器编译的C ++项目,但与过时的libstdc ++链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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