Jump to: navigation, search

Visual Studio

It is recommended to build Boost yourself, as this may avoid some problems and you are able to get the newest version. It is also very easy to do, as auto detection of VS works just fine.

Building Boost

download boost and unzip in %PROGRAMFILES%\boost or something like that
download bjam.exe
copy bjam.exe to boost dir
start a command prompt, and run:
  bjam --toolset=msvc --build-type=complete stage

Note that --build-type=complete builds every possible library combination (unicode/non-unicode, static/dll, etc.) and this takes a long time (several hours on a slow machine) and takes up about 4.6 GB! If you know exactly what libraries you need, you can build just them, but otherwise I would recommend building with low priority, to avoid interfering with other work being done on the computer:

  start /low bjam --toolset=msvc --build-type=complete stage

The resulting libs are place in the stage/ directory. The libraries should be moved to a lib/ directory created in the boost directory.

Visual Studio Setup

Like with all libraries, you have to:

  • add the boost directory as an #include-path, and
  • add the directory with the built libs as a linker-path.

Note that you don't have to specify which libraries to link with, as this is done by header magic!


If you have built boost, errors like

LINK : fatal error LNK1104: cannot open file 'libboost_filesystem-vc90-mt-1_35.lib'

indicate that you either don't have the entered the right path to the libs in VS or you have built only the DLL versions of the boost libraries. The static versions are prepended with 'lib'. Note that:

boost_filesystem-vc90-mt-1_35.lib       is a DLL import library, and
libboost_filesystem-vc90-mt-1_35.lib    is a static library

Mac OS X

If you want to build universal binaries, you'll have to build it manually. Also, MacPorts seems to be very unstable right now, so I'll deprecate using it.

Manual Build

download and install XCode
download boost

Build bjam

cd boost_VERSION/tools/jam/src

Build boost

Example universal binary build:

bjam --toolset=darwin --build-type=complete --with-thread architecture=combined


sudo bjam --prefix=/opt/local/ install

MacPorts Build

sudo port install boost +complete +docs



download boost
download bjam executable for ntx86
unpack boost in c:\boost
unpack bjam in c:\boost
start cmd (building doesn't work in bash)
start /low bjam --toolset=gcc --build-type=complete

Or build a single library:

start /low bjam --toolset=gcc --build-type=complete --with-thread



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

void check(const char *s) {

    static const boost::regex re("h(i|ello)", boost::regex::icase);
    if(regex_match(s, re))
         std::cout << s << " matches.\n";
    else std::cout << s << " doesn't match.\n";

main() {
    check("hi there");

// output:
// HELLO matches.
// hi there doesn't match.

compile with:

g++ -Ic:\boost test-regex.cpp C:\boost\bin.v2\libs\regex\build\gcc-mingw-3.4.5\release\link-static\libboost_regex-mgw34-1_34.a

Here we use the direct specification of a link library. To be able to specify the full path, we ignore the -l option and specify it directly. To quote from the gcc manual:

The only difference between using an -l option and specifying a file name is that -l surrounds library with lib and .a and searches several directories.

Note that the sequence in which the linked objects are specified is significant - it won't work if you exchange the source and the library file; to quote from the gcc manual again:

It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, foo.o -lz bar.o searches library z after file foo.o but before bar.o. If bar.o refers to functions in z, those functions may not be loaded.

... sigh.




emerge -av boost


g++ -lboost_regex test-regex.cpp

... so much easier :).