|
Boost Users : |
Subject: Re: [Boost-users] Boost build and first program
From: Matei David (matei_at_[hidden])
Date: 2014-12-01 15:45:39
On Mon, 1 Dec 2014 16:35:25 +0530
Great Avenger Singh <arsh840_at_[hidden]> wrote:
> Hi I am first time boost user. I build it using following procedure on
> Ubuntu Linux 14.04.
>
> cd /boost-src/
> ./bootstrap.sh and followed instructions. after the completion it gave
> me following suggestion:
>
> The Boost libraries were successfully built.
>
> Following directory should be included to compiler include paths;
> /home/metal-machine/boost-src
> Following directory should be included to linker library paths;
> /home/metal-machine/boost-src/stage/lib
>
>
> Now I try to compile and program with following options from command
> line:
>
> $ g++ -I "/home/metal-machine/boost-src/" -L
> "/home/metal-machine/boost-src/stage/lib/" boostlist.cpp
> -lboost_system -lboost_filesystem -o honey
>
> $ ./honey
>
> ./honey: error while loading shared libraries:
> libboost_system.so.1.57.0: cannot open shared object file: No such
> file or directory
>
>
>
> But on the other hand if I compile and run as follows:
>
> $ g++ boostlist.cpp -lboost_system -lboost_filesystem -o honey
>
> $./honey ->it works fine
>
> I am using thiscode:
> https://gist.github.com/vivithemage/9517678
>
> Where I am doing wrong?
Do you have boost 1.54/1.55 installed in a standard location? Try, eg:
$ locate libboost_system.so
On my 14.04, I see:
/usr/lib/x86_64-linux-gnu/libboost_system.so
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.54.0
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.55.0
So, both 1.54 and 1.55 libs are installed.
If that is the case, what's happening is that with the 2nd command
(the one without -L), gcc ends up using the existing boost, not 1.57
that you just compiled. You can always check what libraries the
executable is using with:
$ ldd honey
To fix this, one option is to install boost 1.57 under /usr/local. Then
you wouldn't need all those gcc options, because 1.57 would be found
ahead of others. I think that's what "b2 install" does.
If that is not an option (eg, no root), you need to install and use
1.57 from a non-standard location. In that case, you need to:
- Tell gcc where to find the boost 1.57 headers at compile time (use
"-I", or better, "-isystem": man gcc).
- Tell gcc where to find the boost 1.57 libs at link time (use "-L")
- Tell ld.so where to find them at run time. (man ld.so)
3 ways to do the last part:
1. Use no other gcc flags, but set environment variable LD_LIBRARY_PATH
before running the executable.
2. Set environment variable LD_RUN_PATH before running gcc.
3. Add gcc option "-Wl,-rpath=${path_to_libs}" (man ld)
M
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net