centos 7默认安装的工具链和LIB库都比较旧,不能很好的编译C++产品,最近踩了很多坑,下面就列一下出来。
问题1: cmake 安装新版之后,版本提示一直是旧版本的解决办法:
properties
wget https://cmake.org/files/v3.12/cmake-3.12.3.tar.gz
tar zxvf cmake-3.*
cd cmake-3.*
./bootstrap --prefix=/usr/local
make
make install
删除旧版本,执行下面的命令
bash
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
问题2: Can't locate IPC/Cmd.pm 问题修复:
// 报错信息:
sql
# ./config
Can't locate IPC/Cmd.pm in @INC (@INC contains: /data/thrid-party/openssl-openssl-3.0.1/util/perl /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 . /data/thrid-party/openssl-openssl-3.0.1/external/perl/Text-Template-1.56/lib) at /data/thrid-party/openssl-openssl-3.0.1/util/perl/OpenSSL/config.pm line 18.
BEGIN failed--compilation aborted at /data/thrid-party/openssl-openssl-3.0.1/util/perl/OpenSSL/config.pm line 18.
Compilation failed in require at /data/thrid-party/openssl-openssl-3.0.1/Configure line 23.
BEGIN failed--compilation aborted at /data/thrid-party/openssl-openssl-3.0.1/Configure line 23.
// 解决办法:
nginx
yum -y install perl-IPC-Cmd
问题3: boost在centos 7 上面的版本偏低是1.54.0偏低:
低版本编译一直提示boost少函数,需要升级boost的更高版本来解决
sql
wget https://sourceforge.net/projects/boost/files/boost/1.78.0/boost_1_78_0.tar.gz --no-check-certificate
tar -xzvf boost_1_78_0.tar.gz
cd boost_1_78_0
./bootstrap.sh --prefix=/usr
./b2 install --with=all
# cp /usr/lib/libboost_unit_test_framework.a /usr/lib64/
**问题4:**centos 默认安装的gcc版本是4.8,需要安装gcc 7版本以上才行
javascript
参考:https://gist.github.com/liuziangexit/888c818a66409e9bbe835002f3c785c7
https://www.cnblogs.com/music-liang/p/12900457.html
操作系统版本查看:
https://cloud.tencent.com/developer/article/1721171
properties
devtoolset:
https://www.imlb6.com/centos-rhel-install-devtoolset/
yum install centos-release-scl -y
yum install devtoolset-9 -y
#临时覆盖系统原有的gcc引用
scl enable devtoolset-9 bash
很多提示gtest编译错误是因为 gcc使用了centos的4.8.5版本导致的,我们需要用下面的命令切换成高版本
bash
source /opt/rh/devtoolset-9/enable
# 查看gcc版本
gcc -v
替换GCC7默认版本
properties
mv /usr/bin/gcc /usr/bin/gcc-4.8.5
ln -s /opt/rh/devtoolset-9/root/bin/gcc /usr/bin/gcc
mv /usr/bin/g++ /usr/bin/g++-4.8.5
ln -s /opt/rh/devtoolset-9/root/bin/g++ /usr/bin/g++
gcc --version
g++ --version
docker 更新 gcc到更高版本:
ruby
https://stackoverflow.com/questions/67090507/how-to-install-gcc-g-9-on-centos-7-docker-centos7
问题5: centos automake 版本默认是1.13,版本过低导致的
错误提示:
go
make[1]: Entering directory '/data/opentelemetry-cpp/thrid-party/libevent-2.1.12-stable'
CC sample/sample_https_client-hostcheck.o
CC sample/sample_https_client-openssl_hostname_validation.o
make[1]: *** No rule to make target 'WIN32-Code/nmake/evconfig-private.h', needed by 'all-am'. Stop.
make[1]: *** Waiting for unfinished jobs....
安装automake:
shell
# wget http://ftp.gnu.org/gnu/automake/automake-1.16.5.tar.gz
# tar -xvf automake-1.16.5.tar.gz
# cd automake-1.16.5/
# ./configure --prefix=/usr/ //本例实际过程中添加了--prefix=/usr/
# make
# make install
# automake --version
参考文档:
javascript
https://github.com/ketoo/NoahGameFrame/issues/60
https://blog.csdn.net/qfturauyls/article/details/109632923
**问题6:**libevent的代码编译
参考文档:
ruby
https://blog.csdn.net/zhouzhiwengang/article/details/132975701
安装:
properties
wget https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz
tar -xvf libevent-2.1.12-stable.tar.gz
cd libevent-2.1.12-stable
./configure
make
make install
# vim /etc/procfile // 添加下面的路径配置export PKG_CONFIG_PATH=/usr/local/openssl/lib/pkgconfig# source /etc/procfile
https://www.cnblogs.com/WindSun/p/12142656.html
**问题7:**openssl 下载:
javascript
wget https://www.openssl.org/source/openssl-3.0.13.tar.gz --no-check-certificate
export PATH="/usr/local/openssl/bin:${PATH}"
export OPENSSL_ROOT_DIR="/usr/local/openssl"
export OPENSSL_CRYPTO_LIBRARY="/usr/local/openssl/lib"
export OPENSSL_INCLUDE_DIR="/usr/local/openssl/include"
参考文档:https://www.cnblogs.com/276815076/p/16799078.html
其他参考文档:
makefile
gtest:
https://installati.one/install-gtest-devel-centos-7/
gmock:
https://installati.one/install-gmock-devel-centos-7/
makecache介绍:
https://blog.csdn.net/A___LEi/article/details/118340579
不同版本docker修改时区:
https://cloud.tencent.com/developer/article/1626811