Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Howto: Install Boost from source

  1. #1
    Join Date
    Mar 2007
    Location
    Coventry, UK
    Beans
    200
    Distro
    Ubuntu 9.10 Karmic Koala

    Howto: Install Boost from source

    Welcome. This a guide on how to install the Boost libraries from source. Although the boost libraries are available in the universe repository there are people who have tried to install from source for one reason or another (myself included) and, because of the unfamiliar method by which Boost choose to create their libraries, fall into trouble or else never really understand what to do (even though it's not all that hard actually).
    This is only a very simple guide on how to get the source compiled and installed and I wont go into more advanced topics on how to customize the installation (because I don't know myself) or on how to cross-compile (since I've tried and given up on that -- the problem being that the boost build system doesn't use the correct cross-compiling binaries for compiling and creating the libraries and it's next to Alchemy trying to understand how to get the thing to use the correct ones. As a last resort, not even creating symlinks from the the cross-compiling binary to the corresponding normal build binary didn't work!).

    -1) General Information

    This guide is specifically written for boost libraries version 1.39.0. The general idea of what we're doing will probably still apply for some of the more recent older library version; but, there will be crucial differences, like the fact that the file configure will exist instead of bootstrap.sh.

    0) Pre-requisites

    0.1)
    You will need the necessary compiling tools (g++, ld, etc...); so, first, install them:
    Code:
    sudo aptitude install build-essential g++
    0.2)
    You will need the source code! Boost's website is not the best when it comes to finding where things are, so just navigate to their getting started page and under the section Get Boost follow the link to the download page and download tar.bz2 file (the tar.7z file has Windows line-terminators, so reading those files in Linux will cause errors). Incidentally, that getting started page is the general reference from which I've derived this guide (along with a bit of trial and much error).

    1) Compile the library

    1.1)
    Go to where you downloaded the directory and uncompress it:
    Code:
    cd download_location
    tar xjf boost_1_39_0.tar.bz2
    Note that the uncompressed source is over 250Mb; so if space is an issue, make the necessary sacrifices!
    Then change directory into the boost directory:
    Code:
    cd ./boost_1_39_0
    1.2)
    Next, we'll need to build the bjam binary and perhaps also set some options on what to compile and where to. Read the next three sub-sections carefully and read it all before you do anything!

    1.2.1)
    Firstly, you will not want to compile the whole boost library since that means compiling a lot of libraries that you don't want or wont use. So, to see a list of the libraries that need compiling, run:
    Code:
    ./bootstrap.sh --show-libraries
    Pick which ones you want and remember them: I'll be choosing filesystem, program_options and system. Note that picking system is needed since it contains the error class that filesystem uses, and I bet that, since the majority of you readers will be looking to compile the filesystem library, this means cutting a few problems out later on for a lot of you!
    What you'll need to run is the command:
    Code:
    ./bootstrap.sh --with-library=filesytem,program_options,system
    But don't do that just yet: keep reading!
    If you do want to compile the whole damned thing, then you don't need to bother with the command above: you'll just run bootstrap.sh as it is:
    Code:
    ./bootstrap.sh
    Again, don't run anything yet: still keep on reading!

    1.2.2)
    Next, you'll need to consider where you want the library installed to. By default, the header files are installed to /usr/local/include, and the libraries themselves are installed to /usr/local/lib. These locations will be more than adequate (it's not recommended to install stuff to /usr/include, /usr/include/lib or /lib); but, if you do want/need to specify a different location, you'll need to run bootstrap.sh like this:
    Code:
    ./bootstrap --libdir=/my/lib/dir --includedir=/my/include/dir
    which will install the libraries to /my/lib/dir and the header files to /my/include/dir.
    Note: there is a bug in that the libraries are installed to /lib and not /usr/local/lib by default; so I'd recommend explicitly telling the build process to install to /usr/local/lib. Do this by adding the flag: --exec-prefix=/usr/local.
    Still, don't run anything yet! Keep reading!

    1.2.3)
    OK, now bring the info from the last two sub-sections together: you'll want the command:
    Code:
    ./bootstrap.sh --exec-prefix=/usr/local --with-libraries=desired_list_of_libs --libdir=/my/lib/dir --includedir=/my/include/dir
    For example, I want to only install the filesystem, program_options, and system libraries, and just to the default lib and include directories; so, I'll personally run:
    Code:
    ./bootstrap.sh --with-libraries=filesystem,program_options,system --exec-prefix=/usr/local
    Having done this (or something similar depending on what you want to do) you'll see the message:
    Bootstrapping is done. To build, run:

    ./bjam

    To adjust configuration, edit 'project-config.jam'.
    Further information:

    - Command line help:
    ./bjam --help

    - Getting started guide:
    http://www.boost.org/more/getting_st...-variants.html

    - Boost.Build documentation:
    http://www.boost.org/boost-build2/doc/html/index.html
    At this point, you can then do the compiling proper...

    1.2.4)
    Run the command:
    Code:
    ./bjam
    And that's it!

    2) Installation

    Immediately after compiling, and before we install them, the header files will be in the directory boost, and the libraries in the directory stage/lib. To install them, just run:
    Code:
    sudo ./bjam install
    Note that, on my system, that command seems to hang for a while; so, give it a chance before killing it.

    Now, there is one "bug" in the installation process. The installation procedure does not create a symlink called libboost_filesystem.so. It's not really a problem, but it's very useful if it does exist. Look in your library directory to see if it's there, or else create it:
    Code:
    sudo ln -s /usr/local/lib/libboost_filesystem-gcc43-mt.so /usr/local/lib/libboost_filesystem.so
    And change /usr/local/lib if you changed where you installed your libraries to at stage 1.2.3, and amend libboost_filesystem-gcc43-mt.so if it's different on your system. (Post a comment if you are having trouble with this since the names will probably be different from system-to-system and don't do anything if you're not at all sure on how libraries are named and symlinked).

    3) Using the libraries

    This bit normally causes a few problems, so read it carefully!

    3.1)
    Include your header files as usual in your code like:
    #include <boost/filesystem.hpp>
    and then tell your compiler where the include libraries are with a -I flag:
    Code:
    g++ -I/usr/local/include/boost-1_39 ...
    If you changed your include directory at stage 1.2.3 by issuing:
    ./bootstrap.sh --includedir=/my/include/dir
    then you'll need to amend the g++ command to:
    Code:
    g++ -I/my/include/dir/boost-1_39
    3.2)
    Then, we'll also need to make sure we can link to the libraries.
    If you did not change the directory to where the libraries are installed to from the default at stage 1.2.3, then simply run:
    Code:
    sudo ldconfig
    And you can start linking the library as usual:
    Code:
    g++ -lboost_filesystem ...
    If you did change the lib directory at stage 1.2.3 by running:
    ./bootstrap.sh --libdir=/my/lib/dir
    then you'll need to run the linking stage as:
    Code:
    g++ -L/my/lib/dir -lboost_filesystem
    Hopefully, that's it! You should now be able to use boost!


    Problems and Updates

    Leave a comment if you have a problem and I'll try to help. But, please, nothing on cross-compiling since I'll go bald trying to figure that one out! Suggestions and experiences on trying to get it to work, however, are welcome.

    Also, improvements and updates to the guide are more than welcome.

  2. #2
    Join Date
    Jul 2009
    Location
    Montevideo
    Beans
    1
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Exclamation Re: Howto: Install Boost from source

    Hi I have followed your guide as much as I could but when I try to compile I still get some errors about boost not being found.

    Code:
    |38|error: boost/filesystem.hpp: No such file or directory|
    |39|error: boost/regex.hpp: No such file or directory|
    |41|error: ‘boost’ has not been declared|
    |41|error: ‘filesystem’ is not a namespace-name|

    The problems I have are in step 2, because it seems is installing the libs in /lib not in /usr/lib

    I am using Code::Block as IDE but it also does not compile with make.

    Very nice guide btw.
    I also dont know why neither 1.38 nor 1.39 boost versions are in the repos

  3. #3
    Join Date
    Mar 2007
    Location
    Coventry, UK
    Beans
    200
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Howto: Install Boost from source

    Sorry for the late-ish reply.

    I tend to avoid IDE's (too bloated), so from the output you posted, it looks like it simply can't find the header files. This could be a problem with Code::Blocks, or with the installation.

    So, look to see if you can compile anything successfully with boost included: just create a very simple file "test.cpp":
    #include <boost/filesystem.hpp>
    int main(void) { return 0; }
    Now, depending on where your boost include files are (they should be in /usr/local/include/boost-1_39), just run:
    Code:
    g++ -E -I/usr/local/include/boost-1_39 test.cpp >/dev/null
    If that last command appears to do nothing and returns successfully, there's no problem in the installation of your header files. In that case, your problem is probably that you haven't told Code::Blocks to include the directory /usr/local/include/boost-1_39 in its include path: you'll have to look for manuals/tutorials on how to modify the IDE's include path.

    Let me know what happens when you issue that command, and I'll continue (I should be able to reply on the same day at the least!)...

  4. #4
    Join Date
    Sep 2009
    Beans
    4

    Re: Howto: Install Boost from source

    Hi,
    I am working on shared memory . I need to use boost interprocess library. I am using eclipse ide and i have installed the boost on linux as explained in the tutorials. Libraries are in /usr/local/include/boost-1_39 and name of library is boost. But when i compile the sample program it gives the following errors.

    g++ -L/usr/local/include/boost-1_39 -o"Gcount" ./ccount.o -lboost
    /usr/bin/ld: cannot find -lboost

    If i compile the same program on terminal still pblm is there.


    Quote Originally Posted by kayvortex View Post
    Sorry for the late-ish reply.

    I tend to avoid IDE's (too bloated), so from the output you posted, it looks like it simply can't find the header files. This could be a problem with Code::Blocks, or with the installation.

    So, look to see if you can compile anything successfully with boost included: just create a very simple file "test.cpp":


    Now, depending on where your boost include files are (they should be in /usr/local/include/boost-1_39), just run:
    Code:
    g++ -E -I/usr/local/include/boost-1_39 test.cpp >/dev/null
    If that last command appears to do nothing and returns successfully, there's no problem in the installation of your header files. In that case, your problem is probably that you haven't told Code::Blocks to include the directory /usr/local/include/boost-1_39 in its include path: you'll have to look for manuals/tutorials on how to modify the IDE's include path.

    Let me know what happens when you issue that command, and I'll continue (I should be able to reply on the same day at the least!)...

  5. #5
    Join Date
    Mar 2007
    Location
    Coventry, UK
    Beans
    200
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Howto: Install Boost from source

    Hi,
    I am working on shared memory . I need to use boost interprocess library. I am using eclipse ide and i have installed the boost on linux as explained in the tutorials. Libraries are in /usr/local/include/boost-1_39 and name of library is boost. But when i compile the sample program it gives the following errors.

    g++ -L/usr/local/include/boost-1_39 -o"Gcount" ./ccount.o -lboost
    /usr/bin/ld: cannot find -lboost

    If i compile the same program on terminal still pblm is there.
    You're telling g++ to find the library "libboost.so" when you type the flag "-lboost". The library wont be called "boost", but probably something like "libboost_interprocess.so"; so you want something like:
    Code:
    g++ -L/usr/local/include/boost-1_39 -o"Gcount" ./ccount.o -lboost_interprocess
    Check to see what the library is actually called, though, since I'm only making an educated guess.

  6. #6
    Join Date
    Sep 2009
    Beans
    4

    Re: Howto: Install Boost from source

    I am installing the boost on itanium (64 bit red hat) machine. I am following the three steps.
    ./bootstrap.sh --prefix=/usr/local
    ./bjam
    ./bjam install

    After installation, libboost files are all located in
    /usr/lib.

    But i am trying to run one simple code.

    #include <boost/interprocess/managed_shared_memory.hpp>
    #include <boost/interprocess/allocators/allocator.hpp>
    #include <boost/interprocess/containers/map.hpp>
    #include <boost/interprocess/containers/string.hpp>
    #include <iostream>

    using namespace boost::interprocess;

    //Typedefs of allocators and containers
    typedef managed_shared_memory::segment_manager segment_manager_t;
    typedef allocator<void, segment_manager_t> void_allocator;
    typedef allocator<char, segment_manager_t> char_allocator;
    typedef basic_string<char, std::char_traits<char>, char_allocator> char_string;

    //Definition of the map holding a string as key and complex_data as mapped type
    typedef std:air<const char_string, int> map_value_type;
    typedef allocator<map_value_type, segment_manager_t> map_value_type_allocator;
    typedef map< char_string, int, std::less<char_string>, map_value_type_allocator> complex_map_type;

    int main ()
    {
    shared_memory_object::remove("MySharedMemory");

    //Create shared memory
    managed_shared_memory segment(create_only,"MySharedMemory", 65536);

    //An allocator convertible to any allocator<T, segment_manager_t> type
    void_allocator alloc_inst (segment.get_segment_manager());

    //Construct the shared memory map and fill it
    complex_map_type *mymap = segment.construct<complex_map_type>("MyMap")(std:: less<char_string>(), alloc_inst);
    char_string cs("test", alloc_inst);

    for(int i = 0; i < 100; ++i)
    {
    mymap->insert(std:air<char_string, int>(cs , i));
    }
    return 0;
    }


    with command
    g++ program_name.cpp -lrt

    It is showing error "No such file and directory" for every header file. This code is working fine on 32 bit (installed by other person).May i know what is the pblm?
    Last edited by man4ish; September 30th, 2009 at 01:53 PM.

  7. #7
    Join Date
    Sep 2009
    Beans
    4

    Re: Howto: Install Boost from source

    I have tried to run the command as suggested by u for checking installation on linux itanium server 64 bit but i am getting the following error. May i know what is the cause of this pblm.

    g++ -E -I/usr/local/include/boost-1_39 boostindex.cpp >/dev/null
    In file included from /usr/local/include/boost-1_39/boost/interprocess/sync/interprocess_mutex.hpp:47,
    from /usr/local/include/boost-1_39/boost/interprocess/mem_algo/rbtree_best_fit.hpp:27,
    from /usr/local/include/boost-1_39/boost/interprocess/detail/managed_memory_impl.hpp:22,
    from /usr/local/include/boost-1_39/boost/interprocess/managed_shared_memory.hpp:21,
    from boostindex.cpp:1:
    /usr/local/include/boost-1_39/boost/interprocess/detail/atomic.hpp:466:2: #error No atomic operations implemented for this platform, sorry!


    Thanks in advance.
    Quote Originally Posted by kayvortex View Post
    You're telling g++ to find the library "libboost.so" when you type the flag "-lboost". The library wont be called "boost", but probably something like "libboost_interprocess.so"; so you want something like:
    Code:
    g++ -L/usr/local/include/boost-1_39 -o"Gcount" ./ccount.o -lboost_interprocess
    Check to see what the library is actually called, though, since I'm only making an educated guess.

  8. #8
    Join Date
    Mar 2007
    Location
    Coventry, UK
    Beans
    200
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Howto: Install Boost from source

    Well, the reason why you appear to be getting "no such file and directory" errors is because you need to tell the compiler to look in the "/usr/local/include/boost-1_39" directory. Just include the flag "-I/usr/local/include/boost-1_39" in your compiling.

    g++ -E -I/usr/local/include/boost-1_39 boostindex.cpp >/dev/null
    In file included from /usr/local/include/boost-1_39/boost/interprocess/sync/interprocess_mutex.hpp:47,
    from /usr/local/include/boost-1_39/boost/interprocess/mem_algo/rbtree_best_fit.hpp:27,
    from /usr/local/include/boost-1_39/boost/interprocess/detail/managed_memory_impl.hpp:22,
    from /usr/local/include/boost-1_39/boost/interprocess/managed_shared_memory.hpp:21,
    from boostindex.cpp:1:
    /usr/local/include/boost-1_39/boost/interprocess/detail/atomic.hpp:466:2: #error No atomic operations implemented for this platform, sorry!
    From the looks of this message, there's a problem with the file "atomic.hpp" for your architecture. Are you sure that you've included all the necessary dependencies for this library? Because the installation process doesn't do this for you: you must read the boost manual and install them all manually.

    Apart from that, there's not much else I can suggest since I neither know enough about the boost interprocess library nor have an IA64 machine to work with to be able to help you. You could try the boost message boards for help.

    Edit: looking at the file "/usr/local/include/boost-1_39/boost/interprocess/detail/atomic.hpp" it looks like you need gcc version 4.0.1 or greater to work on an IA64 machine: which version of gcc are you using?
    Last edited by kayvortex; October 2nd, 2009 at 01:17 AM.

  9. #9
    Join Date
    Sep 2009
    Beans
    4

    Re: Howto: Install Boost from source

    I am using 3.4..6. Now i will try with 4.0.1 version.

    Thanks
    Quote Originally Posted by kayvortex View Post
    Well, the reason why you appear to be getting "no such file and directory" errors is because you need to tell the compiler to look in the "/usr/local/include/boost-1_39" directory. Just include the flag "-I/usr/local/include/boost-1_39" in your compiling.



    From the looks of this message, there's a problem with the file "atomic.hpp" for your architecture. Are you sure that you've included all the necessary dependencies for this library? Because the installation process doesn't do this for you: you must read the boost manual and install them all manually.

    Apart from that, there's not much else I can suggest since I neither know enough about the boost interprocess library nor have an IA64 machine to work with to be able to help you. You could try the boost message boards for help.

    Edit: looking at the file "/usr/local/include/boost-1_39/boost/interprocess/detail/atomic.hpp" it looks like you need gcc version 4.0.1 or greater to work on an IA64 machine: which version of gcc are you using?

  10. #10
    Join Date
    Sep 2008
    Beans
    45

    Re: Howto: Install Boost from source

    I am using Lucid and followed this tutorial to install boost 1.44.
    the application needs a newer version of boost than what is in the repositories.

    I didn't have a full development environment and encountered errors installing boost. So through synaptic, I installed the following to get missing headers.

    libbz2-dev
    python-dev

    Then did a ./bjam -a to rebuild everything. all seems ok now.

    regards
    Last edited by kelargo; August 21st, 2010 at 07:58 PM.

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •