快速解决boost库链接出错的问题(分享)
安装完最新的Boost库
Finally,
$./b2install
willleaveBoostbinariesinthelib/subdirectoryofyourinstallationprefix.YouwillalsofindacopyoftheBoostheadersintheinclude/subdirectoryoftheinstallationprefix,soyoucanhenceforthusethatdirectoryasan#includepathinplaceoftheBoostrootdirectory.
大部分Boost库无需动态或静态编译链接,小部分如regex thread coroutine之类的库在编译自己的源代码时需要加入链接提示
比如在编译使用regex的库时命令如下:
c++-I/usr/local/include/boost/main.cpp-otest1-L/usr/local/lib-lboost_regex
完成后运行时:
LD_LIBRARY_PATH="/usr/local/lib"./test1
否则会报错:
errorwhileloadingsharedlibraries:libboost_regex.so.1.64.0:cannotopensharedobjectfile:Nosuchfileordirectory
这个错误在stackoverflow上给的解释是:
Thelibrarycannotbefound.
Librariesarebydefaultlookedforin/lib,/usr/libandthedirectoriesspecifiedby/etc/ld.so.conf.
Usuallysystemlibraries(likeboost,ifyouinstalleditviayourpackagemanager)arelocatedin/usr/lib,butit'sprobablynotyourcase.
Whereareyourboostlibrarieslocatedonyoursystem?Didyoucompilethembyyourself?Inthiscaseyoushouldtellthedynamiclinkertolookforyourlibrariesinthedirectorythey'relocatedbyusingtheLD_LIBRARY_PATHenvironmentvariable:
LD_LIBRARY_PATH="your/boost/directory"./testfgci
I'dsuggestyoutoinstallboostlibrariesusingyourpackagemanager,anyway,thiswillmakeyourlifealotsimpler.
也就是说系统在运行程序时要先加载动态库,系统的搜寻目录在/etc/ld.so.conf或者/etc/ld.so.conf.d/*.conf中,而该目录中没有链接库所在的位置,要在该文件中手动加入目录地址或者在运行程序之前指定LD_LIBRARY_PATH的值
这样才能正确识别动态库
以上这篇快速解决boost库链接出错的问题(分享)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。