Quick solution to boost library link problems of share
- 2020-05-19 05:18:37
Install the latest Boost library
The official statement includes a sentence:
$ ./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.
Most Boost libraries do not require dynamic or static compilation of links, and a few, such as regex thread coroutine, require a link prompt when compiling their own source code
For example, when compiling a library that USES regex, the command is:
c++ -I /usr/local/include/boost/ main.cpp -o test1 -L /usr/local/lib -lboost_regex
Run time after completion:
Otherwise, an error will be reported:
error while loading shared libraries: libboost_regex.so.1.64.0: cannot open shared object file: No such file or directory
The explanation for this error on stackoverflow is:
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:
I'd suggest you to install boost libraries using your package manager, anyway, this will make your life a lot simpler.
That is system when running the program need to load dynamic libraries, search system directory in/etc/ld so. conf or/etc/ld so. conf. d / *. conf, and no link library location in the directory, to manually add in the file directory address or designated LD_LIBRARY_PATH values before running the program
This is how dynamic libraries are correctly identified