gcc安装
系统默认安装的gcc版本为4.8,在更低版本的CentOS上版本更低,导致很多C、C++新特性不能使用,而我又比较喜欢新东西,所以我就编译安装最新的gcc9.2.0
01依赖项目安装
yum groupinstall -y 'Development Tools'
yum install -y texinfo bison flex gcc-gnat glibc-devel.i686 libgcc.i686
# 安装bison,解决编译中会提示 “WARNING: ‘bison’ is missing on your system.”
# 安装texinfo,解决编译中会提示“WARNING: ‘makeinfo’ is missing on your system”
# 安装i686的包是为了安装32位的头文件和库,如果不安装i686的包,请在configure时加入--disable-multilib,取消对32位的支持。
02安装perl,老版本perl缺少none,导致automake运行报错
wget https://www.cpan.org/src/5.0/perl-5.30.0.tar.gz
tar xvf perl-5.30.0.tar.gz
cd perl-5.30.0
./Configure -des -Dprefix=/data/app
make
make test
make install
03安装autoconf
# 下载autoconf
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.71.tar.xz
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
tar xvf autoconf-2.69.tar.gz
cd autoconf-2.69
./configure --prefix=/apps/darren/local/autoconf
make && make install
04安装automake
# 首先需要安装perl环境
yum install perl perl-devel
yum install perl-Module-Install.noarch
# 安装包解决:找不到EXTERN.h文件的问题
yum install perl-ExtUtils-Embed
yum install perl-Thread-Queue
wget http://ftp.gnu.org/gnu/automake/automake-1.16.tar.gz
tar xvf automake-1.16.tar.gz
cd automake-1.16
./configure --prefix=/usr/local/autoconf
#修改Makefile 查找 /doc\/automake\-$(APIVERSION)
#doc/automake-$(APIVERSION).1: $(automake_script) lib/Automake/Config.pm
# $(update_mans) automake-$(APIVERSION) --no-discard-stderr
#(automake-1.15版本 3686行)加上--no-discard-stderr
#(automake-1.16版本 3694行)加上--no-discard-stderr
make && make install
05安装gmp mpfr mpc
这三个按照顺序安装
tar xvf gmp-6.2.0.tar.xz
tar xvf mpfr-4.0.2.tar.gz
tar cvf mpc-1.1.0.tar.gz
06,设置临时环境变量,编译gcc需要用到
export C_INCLUDE_PATH=/data/app/include:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=/data/app/include:$CPLUS_INCLUDE_PATH
export LD_LIBRARY_PATH=/data/app/lib:/data/app/lib64:$LD_LIBRARY_PATH
export LIBRARY_PATH=/data/app/lib:/data/app/lib64:$LIBRARY_PATH:
安装gcc
我虚拟机电脑2G内存时编译报错,网上说增加交换空间,我懒得划分,直接就划分4内存了
# 下载gcc9.2
wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-9.2.0/gcc-9.2.0.tar.gz
tar -xvf gcc-9.2.0.tar.gz
cd gcc-9.2.0
sh contrib/download_prerequisites
mkdir build && cd build
# 考虑到默认版本为4.8,可能遇到兼容性问题,所以9.2的安装目录自己换一个目录
# ../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib --prefix=/data/app
../configure \
--prefix=/data/app \
--mandir=/data/app/share/man \
--infodir=/data/app/share/info \
--enable-bootstrap \
--enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto \
--enable-shared \
--enable-threads=posix \
--enable-checking=release \
--enable-multilib \
--enable-cet=auto \
--enable-__cxa_atexit \
--enable-gnu-unique-object \
--enable-linker-build-id \
--enable-plugin \
--enable-initfini-array \
--enable-libmpx \
--enable-offload-targets=nvptx-none \
--enable-gnu-indirect-function \
--disable-libgcj \
--disable-libunwind-exceptions \
--with-system-zlib \
--with-gcc-major-version-only \
--with-linker-hash-style=gnu \
--with-isl \
--with-cloog \
--without-cuda-driver \
--with-tune=generic \
--with-arch_32=x86-64 \
--build=x86_64-redhat-linux \
# 编译安装
make && make install
安装gdb
wget http://ftp.gnu.org/gnu/gdb/gdb-8.3.tar.gz
tar xvf gdb-8.3.tar.gz
cd gdb-8.3
./configure --prefix=/data/app/
make && make install
# 我在安装gdb9.1很多文件报错,解决办法是,先升级到gdb8.3,在升级gdb9.1,并且gdb9.1不能直接使用configure文件配置了
mkdir build && cd build
当前路径的绝对路径/configure --prefix=/data/app/
安装cmake
git clone https://github.com/Kitware/CMake.git
cd Cmake
./configure --prefix=/data/app
make && make install
安装ragel
# 安装ragel之前,需要安装colm
wget http://www.colm.net/files/colm/colm-0.13.0.7.tar.gz
tar xvf colm-0.13.0.7.tar.gz
cd colm-0.13.0.7
./configure --prefix=/data/app
make && make install
# 安装ragel
wget http://www.colm.net/files/ragel/ragel-7.0.0.12.tar.gz
tar xvf ragel-7.0.0.12.tar.gz
cd ragel-7.0.0.12
./configure --prefix=/data/app
make && make install
安装protobuf
# 安装protobu依赖
# sudo yum install -y autoconf automake libtool libsysfs make g++ unzip
git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
git submodule update --init --recursive
./autogen.sh
./configure --prefix=/data/app
# 会报如下错误,需要编译安装libtool
+ mkdir -p third_party/googletest/m4
+ autoreconf -f -i -Wall,no-obsolete
configure.ac:30: error: possibly undefined macro: AC_PROG_LIBTOOL
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
autoreconf: /data/app/bin/autoconf failed with exit status: 1
#
wget http://ftp.gnu.org/gnu/libtool/libtool-2.4.6.tar.gz
tar xvf libtool-2.4.6.tar.gz
cd libtool-2.4.6
./configure --prefix=/data/app
make && make install
安装boost库
# 安装icu4c库
git clone https://github.com/unicode-org/icu.git
cd icu/icu4c/source
./configure --prefix=/data/app
make -j2 && make install
# 安装boost库
wget https://nchc.dl.sourceforge.net/project/boost/boost/1.68.0/boost_1_68_0.tar.gz
tar xvf boost_1_68_0.tar.gz
cd boost_1_68_0
./bootstrap.sh --prefix=/data/app \
--with-icu \
--with-toolset=gcc \
--with-libraries=all \
--with-icu=/data/app/lib \
# b2配置参数在文件project-config.jam文件,使用帮助./b2 --help

./b2 && ./b2 install
安装vcpkg
vcpkg可帮助您在 Windows、Linux 和 MacOS 上管理 C 和 C++ 库。这个工具和生态系统正在不断发展,您的参与对它的成功至关重要!
如需获取有关可用命令的简短描述,请执行 vcpkg help。
# 下载
wget https://codeload.github.com/git/git/tar.gz/v2.26.0
tar xvf git-2.26.0.tar.gz
cd git-2.26.0
make prefix=/app all
make prefix=/app install
# 设置全局环境变量
echo "export PATH=$PATH:/app/bin" >>/etc/profile
source /etc/profile
# 查看版本
git --version
# git version 2.26.0
如果之前用yum安装过需要现移除git
yum remove git
安装jsoncpp
wget https://codeload.github.com/open-source-parsers/jsoncpp/tar.gz/1.9.2
tar xvf jsoncpp-1.9.2.tar.gz
cd jsoncpp-1.9.2
mkdir -p build/release
cd build/release
cmake -DCMAKE_BUILD_TYPE=release -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=ON -DARCHIVE_INSTALL_DIR=. -DCMAKE_INSTALL_INCLUDEDIR=include/jsoncpp -G "Unix Makefiles" ../..
make
make install
配置环境变量
vim /etc/profile
# 载文件末尾添加以下内容
# 可执行文件路径
export PATH=/data/app/bin:/data/app/sbin:$PATH
# 动态链接库
LD_LIBRARY_PATH=/data/app/lib:/data/app/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
# 找到静态库的路径
LIBRARY_PATH=/data/app/lib:/data/app/lib64:$LIBRARY_PATH:
export LIBRARY_PATH
# gcc找到头文件的路径
C_INCLUDE_PATH=/data/app/include:$C_INCLUDE_PATH
export C_INCLUDE_PATH
# g++找到头文件的路径
CPLUS_INCLUDE_PATH=/data/app/include:$CPLUS_INCLUDE_PATH
export CPLUS_INCLUDE_PATH
# 为ctags添加别名
alias vctags="ctags -R --c++-kinds=+p --fields=+iaS --extra=+q"
# 退出vim,执行命令
source /etc/profile
# vim打开/etc/ld.so.conf
vim /etc/ld.so.conf
# 添加自己的库目录
# 更新/etc/ld.so.cache文件
/sbin/ldconfig