删除英特尔工具包后,g++ 寻找英特尔数学库并抱怨错误

After removing intel toolkit, g++ looking for intel math library and complain error

这是centos系统。我已经安装了intel HPC toolkit(toolkit before intel oneAPI, including intel c++/c/fortran/MKL...)。然后在我删除英特尔工具包后,我的 g++ 不起作用(我的 gcc 也一样,同样的错误)。似乎 g++ 正在寻找英特尔数学库。由于我删除了intel工具包,它找不到intel数学库并报错。

如何让 g++ 不去寻找 intel 数学库?我怎么知道 g++ 正在寻找什么库?

感谢您的帮助!


C++ 示例

#include<iostream>                                                                                                     #include<cmath>
   int main(){
     int a = 1<<31;
     std::cout<<"a is "<< a <<std::endl;
     int b = std::abs(a);
     std::cout<<"b is "<< b <<std::endl;
     return 0;
   }

我用来编译c++例子的命令

g++ a.cpp

它抱怨的错误

/usr/local/gcc/10.1.0/libexec/gcc/x86_64-pc-linux-gnu/10.1.0/cc1plus: error while loading shared libraries: libsvml.so: cannot open shared object file: No such file or directory

LDD 结果:对于我的 gcc

(base) [Js@XiaoXin13pro ~]$ ldd  /usr/local/gcc/10.1.0/libexec/gcc/x86_64-pc-linux-gnu/10.1.0/cc1plus
        linux-vdso.so.1 =>  (0x00007fffffad5000)
        libisl.so.15 => /usr/local/lib/libisl.so.15 (0x00007f111d980000)
        libmpc.so.3 => /usr/local/lib/libmpc.so.3 (0x00007f111d760000)
        libmpfr.so.4 => /usr/local/lib/libmpfr.so.4 (0x00007f111d4f0000)
        libgmp.so.10 => /usr/local/lib/libgmp.so.10 (0x00007f111d260000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f111d040000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f111cd30000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f111c960000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f111de00000)
        libimf.so => /lib64/libimf.so (0x00007f111c490000)
        libsvml.so => not found
        libirng.so => not found
        libgcc_s.so.1 => /usr/local/gcc/10.1.0/lib64/libgcc_s.so.1 (0x00007f111c260000)
        libintlc.so.5 => not found
        libsvml.so => not found
        libirng.so => not found
        libintlc.so.5 => not found
        libsvml.so => not found
        libirng.so => not found
        libintlc.so.5 => not found
        libsvml.so => not found
        libirng.so => not found
        libintlc.so.5 => not found
        libintlc.so.5 => not found

LDD 结果:对于系统 gcc

(base) [Js@XiaoXin13pro ~]$ ldd /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/cc1plus
        linux-vdso.so.1 =>  (0x00007fffea241000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f225a4e0000)
        libmpc.so.3 => /usr/local/lib/libmpc.so.3 (0x00007f225a2c0000)
        libmpfr.so.4 => /usr/local/lib/libmpfr.so.4 (0x00007f225a050000)
        libgmp.so.10 => /usr/local/lib/libgmp.so.10 (0x00007f2259dc0000)
        libz.so.1 => /lib64/libz.so.1 (0x00007f2259b90000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f2259880000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f22594b0000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f225a800000)
        libimf.so => /lib64/libimf.so (0x00007f2258fe0000)
        libsvml.so => not found
        libirng.so => not found
        libgcc_s.so.1 => /usr/local/gcc/10.1.0/lib64/libgcc_s.so.1 (0x00007f2258db0000)
        libintlc.so.5 => not found
        libsvml.so => not found
        libirng.so => not found
        libintlc.so.5 => not found
        libsvml.so => not found
        libirng.so => not found
        libintlc.so.5 => not found
        libintlc.so.5 => not found

使用 scl 更新 gcc:

sudo yum install centos-release-scl
sudo yum install devtoolset-8-gcc*
scl enable devtoolset-8 bash

检查 gcc

(base) [Js@XiaoXin13pro ~]$ which gcc
/opt/rh/devtoolset-8/root/usr/bin/gcc
(base) [Js@XiaoXin13pro ~]$ gcc --version
gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3)
Copyright (C) 2018 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.

还在抱怨

(base) [Js@XiaoXin13pro ~]$ g++ a.cpp
/opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/cc1plus: error while loading shared libraries: libsvml.so: cannot open shared object file: No such file or directory

和 ldd 结果

(base) [Js@XiaoXin13pro ~]$ ldd /opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/cc1plus
        linux-vdso.so.1 =>  (0x00007ffff5a56000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007fe19add0000)
        libmpc.so.3 => /usr/local/lib/libmpc.so.3 (0x00007fe19abb0000)
        libmpfr.so.4 => /usr/local/lib/libmpfr.so.4 (0x00007fe19a940000)
        libgmp.so.10 => /usr/local/lib/libgmp.so.10 (0x00007fe19a6b0000)
        libz.so.1 => /lib64/libz.so.1 (0x00007fe19a480000)
        libm.so.6 => /lib64/libm.so.6 (0x00007fe19a170000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fe199da0000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fe19b000000)
        libimf.so => /lib64/libimf.so (0x00007fe1998d0000)
        libsvml.so => not found
        libirng.so => not found
        libgcc_s.so.1 => /usr/local/gcc/10.1.0/lib64/libgcc_s.so.1 (0x00007fe1996a0000)
        libintlc.so.5 => not found
        libsvml.so => not found
        libirng.so => not found
        libintlc.so.5 => not found
        libsvml.so => not found
        libirng.so => not found
        libintlc.so.5 => not found
        libintlc.so.5 => not found

我发现有人遇到了同样的错误。它显示在这里 Install OpenMPI from repository with GCC instead of Intel.

为什么 gcc 正在寻找 intel 数学库?在我的示例中,/usr/local/lib 中的 mpc\mpfr\gmp 似乎取决于英特尔库。

我在其他路径搜索了这三个库,但一无所获。我删除了这三个库并通过 sudo yum install gcc 重新安装了 gcc。而且这次效果很好。

上次重装gcc失败,因为yum在/usr/local/lib找到这三个库,没有重装。所以重装依赖库的gcc还是会搜索Intel math library。而这次由于/usr/local/lib中的库被移除,所以yum安装了这三个不依赖于英特尔数学库的库。所以 gcc 不再搜索 intel 数学库了。

我想也许 /usr/local/lib 中的这些库是在我安装 gcc10 时安装的,当时 Intel 库仍然在那里,所以这些库是用 intel 构建的并且依赖于 intel 库。


顺便说一句,this post解释什么是mpc\mpfr\gmp :

GCC depends on:
GMP: GNU Multiple Precision Arithmetic Library
MPFR: GNU Multiple-precision floating-point rounding library
MPC: GNU Multiple-precision C library
ELF: Executable and Linkable Format library
PPL: Parma Polyhedra Library (optional, for memory optimizations)