快速解決boost庫(kù)鏈接出錯(cuò)的問(wèn)題(分享)
安裝完最新的Boost庫(kù)
官方說(shuō)明中有一句話(huà):
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ò):
error while 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ù)
以上這篇快速解決boost庫(kù)鏈接出錯(cuò)的問(wèn)題(分享)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- VS2013安裝配置和使用Boost庫(kù)教程
- C++中Boost.Chrono時(shí)間庫(kù)的使用方法
- visual studio 2015下boost庫(kù)配置教程
- C++中Boost庫(kù)裁剪與其應(yīng)用詳解
- 使用設(shè)計(jì)模式中的單例模式來(lái)實(shí)現(xiàn)C++的boost庫(kù)
- VS2010 boost標(biāo)準(zhǔn)庫(kù)開(kāi)發(fā)環(huán)境安裝教程
- linux中使用boost.python調(diào)用c++動(dòng)態(tài)庫(kù)的方法
- linux下安裝boost庫(kù)的完整步驟記錄
相關(guān)文章
C++ Primer中&、*符號(hào)的多重定義與int *p和int* p的區(qū)別講解
今天小編就為大家分享一篇關(guān)于C++Primer中&、*符號(hào)的多重定義與int *p和int* p的區(qū)別講解,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-04-04解析C++中派生的概念以及派生類(lèi)成員的訪問(wèn)屬性
這篇文章主要介紹了解析C++中派生的概念以及派生類(lèi)成員的訪問(wèn)屬性,是C++入門(mén)學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下2015-09-09C++如何比較兩個(gè)字符串或string是否相等strcmp()和compare()
這篇文章主要介紹了C++如何比較兩個(gè)字符串或string是否相等strcmp()和compare()問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11C語(yǔ)言驅(qū)動(dòng)開(kāi)發(fā)之內(nèi)核使用IO/DPC定時(shí)器詳解
本章將繼續(xù)探索驅(qū)動(dòng)開(kāi)發(fā)中的基礎(chǔ)部分,定時(shí)器在內(nèi)核中同樣很常用,在內(nèi)核中定時(shí)器可以使用兩種,即IO定時(shí)器,以及DPC定時(shí)器,感興趣的可以了解一下2023-04-04C++中?‘=default?’及‘?=delete?’的使用
這篇文章主要介紹了C++中?=default?及?=delete?使用,使用=default和=delete可以控制編譯器默認(rèn)函數(shù)體的使用,下面我們就來(lái)看看具體的室友方法吧,需要的朋友也可以參考一下2021-12-12C語(yǔ)言實(shí)現(xiàn)登錄注冊(cè)和忘記密碼功能
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)登錄、注冊(cè)和忘記密碼功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-12-12C語(yǔ)言通過(guò)深度優(yōu)先搜索來(lái)解電梯問(wèn)題和N皇后問(wèn)題的示例
深度優(yōu)先搜索即是對(duì)一個(gè)新發(fā)現(xiàn)的節(jié)點(diǎn)上如果還關(guān)聯(lián)未探測(cè)到的邊,就沿此邊探測(cè)下去,直到發(fā)現(xiàn)從原點(diǎn)可達(dá)的所有點(diǎn)為止,這里我們就來(lái)展示C語(yǔ)言通過(guò)深度優(yōu)先搜索來(lái)解電梯問(wèn)題和N皇后問(wèn)題的示例2016-06-06Opencv Hough算法實(shí)現(xiàn)圖片中直線檢測(cè)
這篇文章主要為大家詳細(xì)介紹了Opencv Hough算法實(shí)現(xiàn)圖片中直線檢測(cè),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12