Linux 常见错误集锦

环境信息

  • Centos 7

automake

编译安装软件报错

error: require Automake 1.14, but have 1.13.4

Automake 版本不匹配,需要安装 Automake 1.14

$ rpm -qa | grep automake
automake-1.13.4-3.el7.noarch

以下步骤安装 automake-1.14.1

wget http://ftp.gnu.org/gnu/automake/automake-1.14.1.tar.gz
tar -xf automake-1.14.1.tar.gz
cd automake-1.14.1
./bootstrap.sh

以上步骤执行完成后,会生成 configure 可执行文件

./configure
make
make install

安装完成后,执行以下命令验证版本

$ automake --version
automake (GNU automake) 1.14.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Tom Tromey <tromey@redhat.com>
and Alexandre Duret-Lutz <adl@gnu.org>.

makeinfo

编译安装软件报错

makeinfo: command not found

makeinfo 命令不存在,执行以下命令安装

yum install texinfo

gcc

no acceptable C compiler found in $PATH

缺少 gcc 编译器,安装即可

yum install -y gcc

A compiler with support for C++11 language features is required

编译安装软件时报错

configure: error: *** A compiler with support for C++11 language features is required.

错误原因为 gcc 版本太低。查看当前 gcc 版本

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)

安装 gcc-8.3.0

以下步骤演示安装 gcc-8.3.0 [1]

  1. 下载安装包,官方下载地址
    wget ftp://ftp.irisa.fr/pub/mirrors/gcc.gnu.org/gcc/releases/gcc-8.3.0/gcc-8.3.0.tar.gz
    tar -xf gcc-8.3.0.tar.gz
    cd gcc-8.3.0
  2. 编译安装。编译依赖 GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+,需要先按照顺序安装这 3 个依赖。依赖安装参考: 安装 GMP安装 MPFR安装 MPC
    $ ./configure --prefix=/usr/local/gcc-8.3.0 --disable-multilib
    $ make
    $ make install
  3. 安装完成后,需要更新系统标准库 查看当前系统使用的 gcc 库文件,可以看到版本为 libstdc++.so.6.0.19
    $ ls /usr/lib64/libstdc++.so.6
    libstdc++.so.6 libstdc++.so.6.0.19

    $ ls /usr/lib64/libstdc++.so.6 -l
    lrwxrwxrwx 1 root root 19 May 30 08:05 /usr/lib64/libstdc++.so.6 -> libstdc++.so.6.0.19
    执行以下操作,更新 libstdc++.so.6 到最新安装的版本
    $ rm -rf /usr/lib64/libstdc++.so.6

    $ ln -s /usr/local/gcc-8.3.0/lib64/libstdc++.so.6.0.25 /usr/lib64/libstdc++.so.6

    $ ls /usr/lib64/libstdc++.so.6 -l
    lrwxrwxrwx 1 root root 46 Jun 9 09:31 /usr/lib64/libstdc++.so.6 -> /usr/local/gcc-8.3.0/lib64/libstdc++.so.6.0.25

安装 GMP

安装包下载地址

wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
tar -jxvf gmp-6.1.0.tar.bz2
cd gmp-6.1.0
./configure
make && make install

安装 MPFR

安装包下载地址

wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
tar -jxvf mpfr-3.1.4.tar.bz2
cd mpfr-3.1.4
./configure
make && make install

安装 MPC

安装包下载地址

wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
tar -zxvf mpc-1.0.3.tar.gz
cd mpc-1.0.3
./configure
make && make install

cannot find crtn.o

Centos7 编译软件时报错

$ ./configure --prefix=/usr/local/gcc-8.3.0
cannot find crtn.o: No such file or directory

解决方法 : 编译时添加选项 --disable-multilib [2]

$ ./configure --prefix=/usr/local/gcc-8.3.0 --disable-multilib

C++ preprocessor “/lib/cpp” fails sanity check

centos7 编译后,安装软件时报错

error: C++ preprocessor "/lib/cpp" fails sanity chec

该报错原因为缺少必要的 C++ 库,执行以下命令安装

yum install -y gcc-c++

编译安装软件前,执行 configure 时指定 C++ 编译器的路径

在系统上安装了多个版本的 gcc 时,编译前执行 ./configure 时可能会找到默认的 gcc,会不符合版本要求,可能会输出下面代码示例中的错误。./configure 时找到的是 4.8.5 的 GCC,配置此软件需要 4.9,系统上还安装了 8.3.0 版本的 gcc。

$ ./configure --prefix=/usr/local/
checking for C++ compiler vendor... gnu
checking for C++ compiler version... 4.8.5
configure: error: GCC v. 4.9 is required

$ /usr/local/gcc-8.3.0/bin/gcc --version
gcc (GCC) 8.3.0

为了解决此问题,可以在执行 ./configure 时指定编译器的位置,分别可以使用环境变量 CC=/path/to/gccCXX=/usr/local/gcc-8.3.0/bin/g++ 指定 C 和 C++ 编译器的具体路径。

./configure CXX=/usr/local/gcc-8.3.0/bin/g++ --prefix=/usr/local/

./configure CC=/usr/local/gcc-8.3.0/bin/gcc --prefix=/usr/local/

openssl

openssl 版本升级

Centos7 系统默认安装的 openssl 版本太低,需要升级时,可以参考以下步骤升级

查看默认版本

$ openssl version
OpenSSL 1.0.2k-fips 26 Jan 2017

最新版本 OpenSSL 下载地址,此处下载 openssl-1.1.1.tar.gz

wget -k http://www.openssl.org/source/openssl-1.1.1.tar.gz --no-check-certificate

tar -zxvf openssl-1.1.1.tar.gz

cd openssl-1.1.1

./config --prefix=/usr/local/openssl shared zlib

make && make install

此时执行以下命令查看版本会报错

$ /usr/local/openssl/bin/openssl version
/usr/local/openssl/bin/openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory

主要是因为找不到最新版本的动态链接库,可以执行以下命令链接 libssl

ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/
ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib64/

重新检查新编译的 openssl 的版本,显示最新安装的版本

$ /usr/local/openssl/bin/openssl version
OpenSSL 1.1.1 11 Sep 2018

如果旧版本不再使用,执行以下命令使用新的 openssl 版本

$ openssl version
OpenSSL 1.0.2k-fips 26 Jan 2017

$ which openssl
/usr/bin/openssl

$ mv /usr/bin/openssl{,.1.0.2k-fips.bak}

$ ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl

$ openssl version
OpenSSL 1.1.1 11 Sep 2018

make

Something went wrong bootstrapping makefile fragments

源码编译安装软件包,执行 ./configure 报错

config.status: error: Something went wrong bootstrapping makefile fragments
for automatic dependency tracking. If GNU make was not used, consider
re-running the configure script with MAKE="gmake" (or whatever is
necessary). You can also try re-running configure with the
'--disable-dependency-tracking' option to at least be able to build
the package (albeit without support for automatic dependency tracking).
See `config.log' for more details

问题原因 为缺少 GNU make,执行以下命令安装

yum install -y make

脚注