快速解決boost庫鏈接出錯的問題(分享)
安裝完最新的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語言
本文標(biāo)題:快速解決boost庫鏈接出錯的問題(分享)
本文地址:http://www.jygsgssxh.com/a1/Cyuyan/1572.html
您可能感興趣的文章
- 01-10c語言求1+2+...+n的解決方法
- 01-10求子數(shù)組最大和的解決方法詳解
- 01-10c語言 跳臺階問題的解決方法
- 01-10用貪心法求解背包問題的解決方法
- 01-10C語言 解決不用+、-、×、÷數(shù)字運算符做加法
- 01-10fatal error LNK1104: 無法打開文件“l(fā)ibc.lib”的解決方法
- 01-10深入單鏈表的快速排序詳解
- 01-10Linux下semop等待信號時出現(xiàn)Interrupted System Call錯誤(EINTR)解決方法
- 01-10判斷整數(shù)序列是否為二元查找樹的后序遍歷結(jié)果的解決方法
- 01-10c語言中用字符串?dāng)?shù)組顯示菜單的解決方法


閱讀排行
本欄相關(guān)
- 04-02c語言函數(shù)調(diào)用后清空內(nèi)存 c語言調(diào)用
- 04-02func函數(shù)+在C語言 func函數(shù)在c語言中
- 04-02c語言的正則匹配函數(shù) c語言正則表達(dá)
- 04-02c語言用函數(shù)寫分段 用c語言表示分段
- 04-02c語言中對數(shù)函數(shù)的表達(dá)式 c語言中對
- 04-02c語言編寫函數(shù)冒泡排序 c語言冒泡排
- 04-02c語言沒有round函數(shù) round c語言
- 04-02c語言分段函數(shù)怎么求 用c語言求分段
- 04-02C語言中怎么打出三角函數(shù) c語言中怎
- 04-02c語言調(diào)用函數(shù)求fibo C語言調(diào)用函數(shù)求
隨機閱讀
- 04-02jquery與jsp,用jquery
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 01-11ajax實現(xiàn)頁面的局部加載
- 01-10C#中split用法實例總結(jié)
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-10delphi制作wav文件的方法


