1. 程式人生 > >使用CMake編譯時出現動態連結庫錯誤no version information available的解決方案

使用CMake編譯時出現動態連結庫錯誤no version information available的解決方案

出現問題

在使用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)