How to properly link boost libraries in Linux

I'm trying to go through Boost tutorials, but I'm stuck in a link to a file system library.

I have Ubuntu 12.10. The installation was not so difficult

sudo apt-get install libboost-all-dev 

This puts all the headers in / usr / local / include and the compiled sources in / usr / lib /
[--headers]
[--binaries]

I wrote this program [--program]. When I tried to compile it

  g++ -g tut1.cpp -o tut1 -lboost_system -lboost_filesystem 

received the following errors: [--errors].
After a little search http://www.boost.org/doc/libs/1_53_0/more/getting_started/unix-variants.html
I tried this:

 g++ -g -I /usr/local/include/boost/ tut1.cpp -o tut1 -L /usr/lib/libboost_filesystem.a -lboost_system -lboost_filesystem 

but no luck. I had the same mistakes.

Since I can’t post more than two links in a post, here are all the links
http://pastebin.com/DakVFn12

+6
source share
2 answers

I myself found the answer:
http://www.richelbilderbeek.nl/CppLinkErrorUndefinedReferenceToBoostFilesystemDetailGet_current_path_api.htm
It looks like the binaries were not in / usr / lib, but in / usr / local / lib.
So the correct command to compile is:

 g++ -g tut1.cpp -o tut1 -L/usr/local/lib/ -lboost_filesystem 

@Yuushi, that was 1 problem.

+5
source

The -L command should be the base path where the libraries are contained, not the path to a specific library. Use -L /usr/lib/ instead.

+3
source

Source: https://habr.com/ru/post/947707/


All Articles