前言
在Centos7上编译leveldb时报错
error: ‘is_trivially_copy_constructible’ is not a member of ‘std’
原因是Centos7默认装的gcc编译器版本低于5,一般需要额外加–std=c11参数才能用C++11的东西,不怎么会整Cmake,于是简单的解决办法就是升级gcc。注:本篇不考虑编译gcc源码的方案。
升级流程
- 删除旧gcc
yum remove gcc -y
- 通过devtool安装gcc,这里以gcc7为例
yum install centos-release-scl yum install devtoolset-7-gcc devtoolset-7-gcc-c++
- 设置环境变量
# devtool安装的gcc路径在/opt/rh/devtoolset-7/root/usr/bin下,所以需要处理下才能正常使用 $ vi /etc/profile # 写入下面这句 export PATH=$PATH:/opt/rh/devtoolset-7/root/usr/bin #保存完把终端重开一下
- 验证
[root@172 ~]# gcc --version gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5) Copyright (C) 2017 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.
leveldb编译问题处理
如果只是一般使用,上面那样配置后就没啥问题了,然而,编译leveldb时又报错:
[root@172 build]# cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build .
CMake Error at CMakeLists.txt:7 (project):
The CMAKE_C_COMPILER:
/usr/bin/cc
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
CMake Error at CMakeLists.txt:7 (project):
The CMAKE_CXX_COMPILER:
/usr/bin/c++
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
不想改cmakelist,这里我只想到个土办法——软链接
[root@172 build]# ln -s /opt/rh/devtoolset-7/root/usr/bin/gcc /usr/bin/cc
[root@172 build]# ln -s /opt/rh/devtoolset-7/root/usr/bin/g++ /usr/bin/c++
重新执行编译命令
...
[ 94%] Building CXX object CMakeFiles/db_bench.dir/util/histogram.cc.o
[ 95%] Building CXX object CMakeFiles/db_bench.dir/util/testutil.cc.o
[ 96%] Building CXX object CMakeFiles/db_bench.dir/benchmarks/db_bench.cc.o
[ 97%] Linking CXX executable db_bench
[ 97%] Built target db_bench
[ 98%] Building CXX object third_party/googletest/googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.o
[ 98%] Linking CXX static library ../../../lib/libgmock_main.a
[ 98%] Built target gmock_main
[ 99%] Building CXX object third_party/benchmark/src/CMakeFiles/benchmark_main.dir/benchmark_main.cc.o
[100%] Linking CXX static library libbenchmark_main.a
[100%] Built target benchmark_main
成功了,不知道有没有其他更好的方法。