[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Linux Boost installing

Posted on 2011-04-25
Medium Priority
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 http://www.boost.org/doc/libs/1_46_1/more/getting_started/unix-variants.html
it is "/usr/local/boost_1_46_1".

With best regards,
Question by:Alexey Fedorov
  • 8
  • 6
LVL 40

Expert Comment

ID: 35458988
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

by:Alexey Fedorov
ID: 35459247
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 40

Assisted Solution

evilrix earned 1200 total points
ID: 35459411
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.


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

by:Alexey Fedorov
ID: 35459663
Thanks, evilrix!

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

Expert Comment

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

Accepted Solution

Alexey Fedorov earned 0 total points
ID: 35466024
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:
./bootstrap.sh --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:

Seems, that's all?
LVL 40

Expert Comment

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

Author Comment

by:Alexey Fedorov
ID: 35467335
I tested only template/inline features. I'm testing library-based features (like regex) tomorrow.

Author Comment

by:Alexey Fedorov
ID: 35482872
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/ld.so.conf.d 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 libbost_regex.so 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

by:Alexey Fedorov
ID: 35482926
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 40

Assisted Solution

evilrix earned 1200 total points
ID: 35483036
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 40

Expert Comment

ID: 35483047
>> "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

by:Alexey Fedorov
ID: 35752396
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

by:Alexey Fedorov
ID: 35829854
The solution is a quick recipe: it doesn't build debug libraries.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

872 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