雷火电竞-中国电竞赛事及体育赛事平台

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

快速解決boost庫鏈接出錯的問題(分享)

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點擊:

安裝完最新的Boost庫

官方說明中有一句話:

Finally,

$ ./b2 install
will leave Boost binaries in the lib/ subdirectory of your installation prefix. You will also find a copy of the Boost headers in the include/ subdirectory of the installation prefix, so you can henceforth use that directory as an #include path in place of the Boost root directory.

大部分Boost庫無需動態(tài)或靜態(tài)編譯鏈接,小部分如regex   thread   coroutine之類的庫在編譯自己的源代碼時需要加入鏈接提示

比如在編譯使用regex的庫時命令如下:

c++ -I /usr/local/include/boost/ main.cpp -o test1 -L /usr/local/lib -lboost_regex

完成后運行時:

LD_LIBRARY_PATH="/usr/local/lib" ./test1  

否則會報錯:

error while loading shared libraries: libboost_regex.so.1.64.0: cannot open shared object file: No such file or directory

這個錯誤在stackoverflow上給的解釋是:

The library cannot be found.

Libraries are by default looked for in /lib, /usr/lib and the directories specified by /etc/ld.so.conf.

Usually system libraries (like boost, if you installed it via your package manager) are located in /usr/lib, but it's probably not your case.

Where are your boost libraries located on your system? Did you compile them by yourself? In this case you should tell the dynamic linker to look for your libraries in the directory they're located by using the LD_LIBRARY_PATH environment variable:

LD_LIBRARY_PATH="your/boost/directory" ./testfgci
I'd suggest you to install boost libraries using your package manager, anyway, this will make your life a lot simpler.

也就是說系統(tǒng)在運行程序時要先加載動態(tài)庫,系統(tǒng)的搜尋目錄在/etc/ld.so.conf或者/etc/ld.so.conf.d/*.conf中,而該目錄中沒有鏈接庫所在的位置,要在該文件中手動加入目錄地址或者在運行程序之前指定LD_LIBRARY_PATH的值

這樣才能正確識別動態(tài)庫

以上這篇快速解決boost庫鏈接出錯的問題(分享)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持我們。

上一篇:華為機試題之統(tǒng)計單詞個數(shù)實例代碼

欄    目:C語言

下一篇:c++ 端口掃描程序?qū)崿F(xiàn)案例

本文標(biāo)題:快速解決boost庫鏈接出錯的問題(分享)

本文地址:http://www.jygsgssxh.com/a1/Cyuyan/1572.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有