13

I've been trying to go through Boost tutorials but I got stuck at linking the filesystem library.

I have Ubuntu 12.10. Installation wasn't that hard

sudo apt-get install libboost-all-dev 

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

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

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

got this errors: [--errors].
After a little search on 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 didn't have luck. I had the same errors.

Since I cannot put more than 2 links in the post, here are all links
http://pastebin.com/DakVFn12

2
  • Try reversing the order of the libraries in your link command. Commented Jun 20, 2013 at 6:37
  • Avoid external links... they may get broken! Commented Jul 13, 2015 at 20:02

2 Answers 2

10

I found the answer myself here:
http://www.richelbilderbeek.nl/CppLinkErrorUndefinedReferenceToBoostFilesystemDetailGet_current_path_api.htm
Looks like binaries weren't in /usr/lib but in /usr/local/lib.
So the correct command for compilation would be:

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

@Yuushi, that was 1 problem.

Sign up to request clarification or add additional context in comments.

4 Comments

I doubt apt-get install libboost-dev-all put stuff in /usr/local.
I don't know where you got your package, but Ubuntu 12.10's libboost-dev package just pulls in libboost1.49-dev which puts everything in /usr (including filesystem and system)
its apt-get install libboost-all-dev
How to link everything from boost?
4

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

1 Comment

find /usr/lib -name "*boost*"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.