程序笔记   发布时间:2022-05-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了快速解决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库无需动态或静态编译链接,小部分如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的值

这样才能正确识别动态库

以上这篇快速解决boost库链接出错的问题(分享)就是小编分享给大家的全部内容了,希望能给大家一个参,也希望大家多多支持编程小技巧。

大佬总结

以上是大佬教程为你收集整理的快速解决boost库链接出错的问题(分享)全部内容,希望文章能够帮你解决快速解决boost库链接出错的问题(分享)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。