hongbin
hongbin

Reputation: 187

how to make sure that boost is successfully installed?

I'm tring to install a linux tool that explicitly claims boost installation is necessary.(http://www.statmt.org/moses/?n=Development.GetStarted)

I've downloaded the source code of boost1.42(put in /usr/local/boost1.42) to compile it. Though the compile process produces a lot of errors and warnings(Is it normal? the boost official website says that there should not be other errors but for IO errors.), Finally I got the /stage/lib and /boost in the /usr/local/boost1.42 directory. Now I could run examples like:

 #include <boost/regex.hpp>
#include <iostream>
#include <string>

int main()
{
    std::string line;
    boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );

    while (std::cin)
    {
        std::getline(std::cin, line);
        boost::smatch matches;
        if (boost::regex_match(line, matches, pat))
            std::cout << matches[2] << std::endl;
    }
}

 $ c++ -I /usr/local/boost_1_42_0 example.cpp -o example -L~/usr/local/boost_1_42_0/stage/lib/ -lboost_regex

this will actually emit a excutable file "example", with no compile warnings and correct behavior. But when I want to see its linkage details with:

$ldd -v example

the result is quite confusing:

    linux-vdso.so.1 =>  (0x00007fffb4b9c000)
    libboost_regex.so.1.42.0 => not found
    libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003f79600000)
    libm.so.6 => /lib64/libm.so.6 (0x0000003f72e00000)
    libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003f78e00000)
    libc.so.6 => /lib64/libc.so.6 (0x0000003f72200000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003f72a00000)
    /lib64/ld-linux-x86-64.so.2 (0x0000003f71e00000)

    Version information:
    ./example:
            libgcc_s.so.1 (GCC_3.0) => /lib64/libgcc_s.so.1
            libpthread.so.0 (GLIBC_2.2.5) => /lib64/libpthread.so.0
            libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
            libstdc++.so.6 (CXXABI_1.3) => /usr/lib64/libstdc++.so.6
            libstdc++.so.6 (GLIBCXX_3.4) => /usr/lib64/libstdc++.so.6
    /usr/lib64/libstdc++.so.6:
            libm.so.6 (GLIBC_2.2.5) => /lib64/libm.so.6
            ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2
            libgcc_s.so.1 (GCC_4.2.0) => /lib64/libgcc_s.so.1
            libgcc_s.so.1 (GCC_3.3) => /lib64/libgcc_s.so.1
            libgcc_s.so.1 (GCC_3.0) => /lib64/libgcc_s.so.1
            libc.so.6 (GLIBC_2.4) => /lib64/libc.so.6
            libc.so.6 (GLIBC_2.3) => /lib64/libc.so.6
            libc.so.6 (GLIBC_2.3.2) => /lib64/libc.so.6
            libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
    /lib64/libm.so.6:
            libc.so.6 (GLIBC_PRIVATE) => /lib64/libc.so.6
            libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
    /lib64/libgcc_s.so.1:
            libc.so.6 (GLIBC_2.4) => /lib64/libc.so.6
            libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
    /lib64/libc.so.6:
            ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2
            ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2
    /lib64/libpthread.so.0:
            ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2
            ld-linux-x86-64.so.2 (GLIBC_2.2.5) => /lib64/ld-linux-x86-64.so.2
            ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2
            libc.so.6 (GLIBC_2.3.2) => /lib64/libc.so.6
            libc.so.6 (GLIBC_PRIVATE) => /lib64/libc.so.6
            libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6

It seems that the linker didn't find the libboost_regex.a in /usr/local/boost1.42/stage/lib/libboost_regex.a (see ldd log: libboost_regex.so.1.42.0 => not found).

So which libary does it really wants to load? why "not found" turns out to produce the right excutable file?

And if I want to make sure boost is successfully installed, do I have to export the /usr/local/boost1.42 and /usr/local/boost1.42/stage/lib to anywhere, so that other programs could know its location?

Thanks! Hongbin

Upvotes: 0

Views: 2695

Answers (2)

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136435

To install boost in a non-standard location (not specified in ld.so.conf) and use it do:

  1. Configure boost with --prefix and --libdir options:

    $ ./bootstrap.sh --prefix=${PREFIX} --libdir=${PREFIX}/lib64
    
  2. Build and install boost setting rpath to the same value as --libdir, e.g. ${PREFIX}/lib64:

    $ ./b2 -d+2 --layout=system variant=release link=shared threading=multi runtime-link=shared linkflags="-Wl,-rpath,${PREFIX}/lib64"
    
    $ sudo ./b2 -d+2 --layout=system variant=release link=shared threading=multi runtime-link=shared linkflags="-Wl,-rpath,${PREFIX}/lib64" install
    
  3. Compile your application specifying boost include directory:

    $ g++ -c -I${PREFIX}/include ...
    
  4. Link you application specifying boost lib location. Also embed rpath in the binaries, so that the application can find boost libraries without having to fiddle with LD_LIBRARY_PATH:

    $ g++ -L${PREFIX}/lib64 -Wl,-rpath,${PREFIX}/lib64 ...
    

In the above set PREFIX to boost install location, e.g. export PREFIX=/usr/local/my_boost.

Upvotes: 3

Mat
Mat

Reputation: 206851

Yes, you need to tell the dynamic linker where the shared objects (.so files, not .a files) are located.

This can be done by setting LD_LIBRARY_PATH to the right path (and exporting that), or editing /etc/ld.so.conf (or some other settings file depending on the distribution).

(Another option is to use rpath options while linking the executable, but the environment settings are more flexible for development.)

Upvotes: 0

Related Questions