使用CMake编译时出现动态链接库错误no version information available的解决方案
程序员文章站
2022-06-25 18:44:48
...
出现问题
在使用cmake编译时出现如下错误:
/usr/local/bin/cmake: /home/0123/anaconda2/lib/libssl.so.1.0.0: no version information available (required by /usr/local/lib/libcurl.so.4)
/usr/local/bin/cmake: /home/0123/anaconda2/lib/libssl.so.1.0.0: no version information available (required by /usr/local/lib/libcurl.so.4)
/usr/local/bin/cmake: /home/0123/anaconda2/lib/libcrypto.so.1.0.0: no version information available (required by /usr/local/lib/libcurl.so.4)
提示信息指出cmake用到的库被链到了home目录的anaconda2里,但实际需要的是/usr/local/lib目录下的库。
查找原因
执行命令查看cmake的动态链接库:
$ ldd /usr/local/bin/cmake
/usr/local/bin/cmake: /home/0123/anaconda2/lib/libssl.so.1.0.0: no version information available (required by /usr/local/lib/libcurl.so.4)
/usr/local/bin/cmake: /home/0123/anaconda2/lib/libssl.so.1.0.0: no version information available (required by /usr/local/lib/libcurl.so.4)
/usr/local/bin/cmake: /home/0123/anaconda2/lib/libcrypto.so.1.0.0: no version information available (required by /usr/local/lib/libcurl.so.4)
linux-vdso.so.1 => (0x00007ffe469e7000)
libz.so.1 => /home/0123/anaconda2/lib/libz.so.1 (0x00007fb7375af000)
libcurl.so.4 => /usr/local/lib/libcurl.so.4 (0x00007fb737340000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb7370fd000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fb736ef8000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fb736cf0000)
libstdc++.so.6 => /home/0123/anaconda2/lib/libstdc++.so.6 (0x00007fb7369b6000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb7366af000)
libgcc_s.so.1 => /home/0123/anaconda2/lib/libgcc_s.so.1 (0x00007fb73649d000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb7360d4000)
libssl.so.1.0.0 => /home/0123/anaconda2/lib/libssl.so.1.0.0 (0x00007fb735e5d000)
libcrypto.so.1.0.0 => /home/0123/anaconda2/lib/libcrypto.so.1.0.0 (0x00007fb735a1d000)
/lib64/ld-linux-x86-64.so.2 (0x000055bc1482f000)
解决方案
将需要用到的动态链接库目录export到$LD_LIBRARY_PATH环境变量
中,并将该语句加到~/.bashrc
中,并执行source ~/.bashrc
生效,重新开启Terminal再执行,错误解决。
$ vi ~/.bashrc
$ export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH 添加到文件中并保存
$ source ~/.bashrc
此时再查看cmake的动态链接库正常
$ ldd /usr/local/bin/cmake
linux-vdso.so.1 => (0x00007ffee1f5c000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f04b2b34000)
libcurl.so.4 => /usr/local/lib/libcurl.so.4 (0x00007f04b28c5000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f04b26a7000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f04b24a2000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f04b229a000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f04b1f87000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f04b1c80000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f04b1a69000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f04b16a0000)
libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f04b1440000)
libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f04b1064000)
/lib64/ld-linux-x86-64.so.2 (0x0000564484ae6000)