boost庫(kù)鏈接出錯(cuò)怎么辦

這篇文章將為大家詳細(xì)講解有關(guān)boost庫(kù)鏈接出錯(cuò)怎么辦,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

薩爾圖網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、APP開(kāi)發(fā)、自適應(yīng)網(wǎng)站建設(shè)等網(wǎng)站項(xiàng)目制作,到程序開(kāi)發(fā),運(yùn)營(yíng)維護(hù)。創(chuàng)新互聯(lián)公司2013年成立到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來(lái)保證我們的工作的順利進(jìn)行。專(zhuān)注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)。

安裝完最新的Boost庫(kù)

官方說(shuō)明中有一句話:

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庫(kù)無(wú)需動(dòng)態(tài)或靜態(tài)編譯鏈接,小部分如regex   thread   coroutine之類(lèi)的庫(kù)在編譯自己的源代碼時(shí)需要加入鏈接提示

比如在編譯使用regex的庫(kù)時(shí)命令如下:

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

完成后運(yùn)行時(shí):

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

否則會(huì)報(bào)錯(cuò):

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

這個(gè)錯(cuò)誤在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.

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

這樣才能正確識(shí)別動(dòng)態(tài)庫(kù)

關(guān)于“boost庫(kù)鏈接出錯(cuò)怎么辦”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

網(wǎng)頁(yè)名稱(chēng):boost庫(kù)鏈接出錯(cuò)怎么辦
鏈接分享:http://muchs.cn/article30/ippdso.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊(cè)、外貿(mào)建站面包屑導(dǎo)航、ChatGPT小程序開(kāi)發(fā)、網(wǎng)站策劃

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

小程序開(kāi)發(fā)