Linux Boost installing

Posted on 2011-04-25
Last Modified: 2012-05-11
Hi, guys!

I'm new in Linux/C++/GCC developing, so, there is a silly question: what's the right typical directory to install BOOST in?

According to
it is "/usr/local/boost_1_46_1".

With best regards,
Question by:alexf2
    LVL 39

    Expert Comment

    Installling and building Boost from scratch can be a painful experience if you are not familiar with the process. Nearly all popular flavours of Linux distros that support package installations will include Boost as a package. Unless you need the current most up to date version (1.46) you are better off installing the latest package that is available for your distro.

    Author Comment

    I'm on Centos 5.6 (upgraded from 5.5).

    "yum search boost" shows:

    boost.i386 : The Boost C++ Libraries
    boost-debuginfo.i386 : Debug information for package boost
    boost-devel.i386 : The Boost C++ headers and development libraries
    boost-doc.i386 : The Boost C++ html docs
    boost141.i386 : The free peer-reviewed portable C++ source libraries
    boost141-date-time.i386 : Runtime component of boost date-time library
    boost141-devel.i386 : The Boost C++ headers and shared development libraries
    boost141-doc.i386 : HTML documentation for the Boost C++ libraries
    boost141-filesystem.i386 : Runtime component of boost filesystem library
    boost141-graph.i386 : Runtime component of boost graph library
    boost141-graph-mpich2.i386 : Runtime component of parallel boost graph library
    boost141-graph-openmpi.i386 : Runtime component of parallel boost graph library
    boost141-iostreams.i386 : Runtime component of boost iostreams library
    boost141-math.i386 : Stub that used to contain boost math library
    boost141-mpich2.i386 : Runtime component of Boost.MPI library
    boost141-mpich2-devel.i386 : Shared library symlinks for Boost.MPI
    boost141-mpich2-python.i386 : Python runtime component of Boost.MPI library
    boost141-openmpi.i386 : Runtime component of Boost.MPI library
    boost141-openmpi-devel.i386 : Shared library symlinks for Boost.MPI
    boost141-openmpi-python.i386 : Python runtime component of Boost.MPI library
    boost141-program-options.i386 : Runtime component of boost program_options library
    boost141-python.i386 : Runtime component of boost python library
    boost141-regex.i386 : Runtime component of boost regular expression library
    boost141-serialization.i386 : Runtime component of boost serialization library
    boost141-signals.i386 : Runtime component of boost signals and slots library
    boost141-static.i386 : The Boost C++ static development libraries
    boost141-system.i386 : Runtime component of boost system support library
    boost141-test.i386 : Runtime component of boost test library
    boost141-thread.i386 : Runtime component of boost thread library
    boost141-wave.i386 : Runtime component of boost C99/C++ preprocessing library
    mod_python.i386 : An embedded Python interpreter for the Apache Web server.
    perl-Boost-Graph.i386 : Interface to the Boost-Graph C++ libraries
    python26-mod_python.i386 : An embedded Python interpreter for the Apache HTTP Server

    Open in new window

    My project's QuickFast library requires: BOOST V 1.36.0 or later.
    So, I could install boost141 packagesm but I don't see any "debug" packages for 141.
    LVL 39

    Assisted Solution

    1.36 is very old. As long as QuickFast doesn't have an ABI dependency on that version of Boost it should work with 1.41.

    You need to install the dev package. This will install all the headers and libraries required for development.


    Author Comment

    Thanks, evilrix!

    For today, I decided to attempt building the boost latest version.
    LVL 39

    Expert Comment

    Understood. Let me know if you run into any issues and I'll try and assist.

    Accepted Solution

    I built "boost". Quite straightforwardly.

    1. tar --bzip2 -xf /path/to/boost_1_46_1.tar.bz2
    into /usr/local

    2. Went into /usr/local/boost_1_46_1 and started:
    ./ --with-libraries=date_time,filesystem,iostreams,math,program_options,random,regex,serialization,signals,system,thread

    3. ./bjam

    4. ./bjam install

    As the result I got the headers copy in /usr/local/include/boost and built libs in /usr/local/lib.

    Now, I have to set environment variables:
     2) INCLUDE.

    Seems, that's all?
    LVL 39

    Expert Comment

    Great, if that now all works for you go ahead and select your last post as the solution.

    Author Comment

    I tested only template/inline features. I'm testing library-based features (like regex) tomorrow.

    Author Comment

    I run into problems using "boost" shared libs.

    1. I tried to set LD_LIBRARY_PATH under CentOS. I added custom_libs.conf into /etc/ containing /usr/local/lib - path to boost libraries. But my program was unable to find libs. Only
    export /usr/local/lib helped.

    2. I unable to link "boost" statically.

    g++ -c   -o "Release/hello.o" -I/usr/local/boost_1_46_1  hello.cpp
    g++ -c   -o "Release/test.o" -I/usr/local/boost_1_46_1  test.cpp
    g++  -static -L/usr/local/lib -lboost_regex -o "Release/Hello" Release/hello.o Release/test.o 

    Open in new window

    My HelloWorld app. links regex to test shared boost libs.
    Both: libboost_regex.a and are at /usr/local/lib, but the compiller is unable to link:

    undefined reference to `boost::basic_regex<wchar_t...,

    Open in new window

    3. "Debug" build with shared "boost" doesn't work, only "Release" works.

    g++ -c  "-D_GLIBCXX_DEBUG" -g -ggdb3 -o "Debug/hello.o" -I/usr/local/boost_1_46_1  hello.cpp
    g++ -c  "-D_GLIBCXX_DEBUG" -g -ggdb3 -o "Debug/test.o" -I/usr/local/boost_1_46_1  test.cpp
    g++  -g -L/usr/local/lib -lboost_regex -o "Debug/Hello" Debug/hello.o Debug/test.o 

    Open in new window

    "Debug" executable fails with "segmentation fault" or

    Hello: /usr/local/boost_1_46_1/boost/regex/v4/match_results.hpp:517: void boost::match_results<BidiIterator, Allocator>::set_first(BidiIterator) [with BidiIterator = const wchar_t*, Allocator = std::allocator<boost::sub_match<const wchar_t*> >]: Assertion `m_subs.size() > 2' failed.

    Open in new window


    Author Comment

    Here is my test for boost shared and "include only" parts.

    #include <stdlib.h>
    #include <stdio.h>
    #include <wchar.h>
    #include <locale.h>
    #include <boost/lambda/lambda.hpp>
    #include <boost/regex.hpp>
    #include <memory>
    #include <list>
    #include <iterator>
    #include <iostream>
    #include <algorithm>
    #include "test.h"
    typedef std::istream_iterator<int> in;
    void TestBoost ()
    	boost::wregex regEx(L"^1238*");
    	boost::wcmatch matches;
    	boost::regex_search(L"1238891", matches, regEx);
    	wprintf(L"Matches: ");
    	for (int i = 0; i < matches.size(); ++i)
    		wprintf(L"[%ls:%d],", matches[ i ].str().c_str(), matches[ i ].str().length() );		
    	using namespace boost::lambda;
    	std::for_each(in(std::cin), in(), std::wcout << (_1 * 3) << L" ");

    Open in new window

    Debug build:
    boost::regex_search(L"1238891", matches, regEx); - fails with error shown in previous post.
    boost::regex_match - fails with segmentation fault.

    LVL 39

    Assisted Solution

    I suspect your issue is related to your linking order.

    You need to link to the library after you link the rest of your code.

    g++  -static -o "Release/Hello" Release/hello.o Release/test.o -L/usr/local/lib -lboost_regex

    The linker needs to know what symbols to extract from boost_regex. It will not know if you link to it first. Once the linker has seen a library it will not consider it again. Linking generally happens in a strict left to right order.
    LVL 39

    Expert Comment

    >> "Debug" executable fails with "segmentation fault" or
    Assertions only fire in debug builds, not release. The fact you have an assertion indicates a problem with your code, it does not necessarily mean there is a problem with boost. Also the fact it might segv in debug and not release is probably because the debug memory footprint is different from the release footprint and so you see different behaviour (by chance, not design).

    Author Comment

    Hi, evilrix! Excuse me for the daly: I had to switch hardly to a regular work related to Windows :-) Soon I'm returning back. I haven't got a shance to try yours suggestions yet, but I do it soon. The main problem it seems: I haven't built debug boost libs, so the debug program code is linked to release boost leading to "segmentation fault". I faced the same problem trying to make a debug build with CRT code (glibc, atdc, etc...) in order to step into libs (into "printf", for example). Static build was perfect: it worked and I was able to step into CRT-libs, but dynamic build crushed with "segmentation fault" inside of CRT function "atexit". It was because during execution release glibc was loded instead of debug.

    Formerly, I increased the Q. points up to 500 :-)


    Author Closing Comment

    The solution is a quick recipe: it doesn't build debug libraries.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
    Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now