解决Boost库链接出错问题
2018-06-17 22:32:36来源:未知 阅读 ()
安装完最新的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库无需动态或静态编译链接,小部分如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.
也就是说系统在运行程序时要先加载动态库,系统的搜寻目录在/etc/ld.so.conf或者/etc/ld.so.conf.d/*.conf中,而该目录中没有链接库所在的位置,要在该文件中手动加入目录地址或者在运行程序之前指定LD_LIBRARY_PATH的值
这样才能正确识别动态库
------------------------------------------------------------------------------------------------------------
更新:
一个更方便的方法是在IDE的environment variable中添加LD_LIBRARY_PATH=/usr/local/lib
然后运行即可,要不然只能使用terminal来运行
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- 关于各种不同开发语言之间数据加密方法(DES,RSA等)的互通的 2020-06-07
- C++ 函数和链接性 2020-05-18
- C++ 静态持续变量 2020-05-10
- gcc/g++ 链接顺序注意事项 2020-04-20
- G++编译链接的那些事!G++的特殊使用方法[常用] 2020-04-19
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash