Learning C++ 0x - Building Boost Library for Visual C++

As part of understanding TR1, for the first time I’ve decided to try with Boost in fact I heard this word quite long time ago. TR1 introduces 14 new components the fact is that 10 of them are inspired from the Implemented boost library. The boost founder members are also part of C++ Standard Committee . Boost Compilers are portable and possible to build using different type of compilers like GNU C++, Intel C++ compiler ofcourse Microsoft C++ compiler 6.0 to 2005 can be used to compile Boost Libraries under Windows.

Earlier my decision was to use CygWin environment in my machine and use GNU C++ compiler which has already providing some functionalities of TR1. But it was rather difficult for me. Anyway I left that idea and now I compiled boost under Windows using Visual C++ (2005) 8.0 compiler . Visual Studio 2003 and Visual C++ 2005 and also Visual C++ 6.0 working together without any problems in my machine.

My first try was with Visual C++ 2003 compiler because in the documentation (when I downloaded first) it was specified that bjam (will explain later) only till Visual C++ 2003 (7.1) compiler (I’m not sure I’m missed about Visual C++ 8.0) . The library had built and created as many folderd in the target folder but those folders neither contain any libraries nor DLL. I don’t what really happened. So my try with Visual C++ 7.1 end in tears.

Just after a week I searched the boost documentation regarding configuring with Visual C++ 2005. Yea! this time bjam suppports build with Visual C++ 8.0

So confused on reading all these?

Ok let me explain each and every one.

1. What’s Boost?

Boost is a free, peer reviewed library which is highly portable across different compilers and operating systems and purely based on Ansi C++ standard. Have a look at Boost.org to know more about Boost

2. What’s TR1?

TR1 is the proposed template library for the next version of C++ (C++ 0x). Also a new proposal named TR2 also exists there. There are 14 new components in the TR1, and 10 among them are inspired from Boost Library

3. What is bjam?

Boost.Jam (BJam)  is a build tool based on FTJam, which in turn is based on Perforce Jam. It contains significant improvements made to facilitate its use in the Boost Build System, but should be backward compatible with Perforce Jam ( just copied the sentences from Boost :) ). Check the boost documentation to know more about Boost Jam

4. How to setup Boost in your machine?

Ok I shall explain side side setup for prepaing boost using Visual C++ compiler

1. Download latest version of Boost from Boost.org. The Boost Project is hosted at by Sourceforge.net. Choose Download Boost from Pckages menu

2. Since we are setting up using Visual Studio under windows, download boost package (e.g Boost_1_33_1.exe) for windows.

3. Extract the downloaded .exe (or zip) file to permanant place. e.g C:\Program Files\Boost_1_33_1 )

4. Now you have to build the bjam (build tool for Boost) to get bjam executable. You can also download the Pre-Built bjam files from Sourceforge.net. Before building bjam, take a look at the follownig priliminary setup

a. I compiled using Visual C++ 8.0 compiler (Shipped with Visual Studio 2005). You can also use Visual C++ 6.0, Visual C++ 7.1

b. Before you starting there are some priilminary steps for easy building. Go to the vc\bin folder of Visual Studio Installation directory (e.g c:\Program Files\Microsoft Visual Studio 8) .

c.Execute the vcvars32.bat in the bin folder to setup the environment variables and other options for the compiler. This is really important if you are installed different Visual C++ compilers in your system. You should make sure that you are setting up the environment for the desired compiler.

d. You can check the compiler version by taking Run->cmd.exe (cmd) and hitting enter key after typing cl ( or cl.exe)

e. It will show the version of Microsoft C++ compiler.

f. I could not setup the proper compiler for use even after setting up the vcvars32.bat of my desired compiler. You can manually modify the location of the compiler in the envirnment variables of the system. Edit the Path value of System Variable (you can also add a new variable) from the environment variables. Add the bin folder of you visual studio (don’t forget to remove if the bin folder of previous version or other version of compiler existing in the path varible. You can seperate the variables using ‘;‘. Now the system will locate the proper CL.exe after evaluating this environment variable. repeat step 4.D after closing the console window or takign a new window (the environment variables will be read on initializing the application so the newly added or modified variable may not be updated). To add envirnment variables Open My computer Properties->Advanced Tab->Environment Varibales

g. You may face error with Visual C++ 8.0 by could not locating mspdb80.dll to start cl.exe. You will not face any error if you are compiling normal project from Visual Studio IDE. Why it’s not showing error at that time? Some people through some forums suggest that download the missing DLL from dll-files.com and copy to the system32 folder. Don’t do that. The required dll will be there inside the (VS_ROOT)\Common\IDE (e.g. D:\Program Files\Microsoft Visual Studio 8\Common7\IDE) folder. You can locate the mpssb80.dll inside the specified folder. If it is not existing there it’s sure that theres’ some problem with your installation. So if you face an error because of missing mspdb80.dll, please add the IDE directory to the Path of system environment variables.

h. Sometimes you may also need to add the Include path of (either of platform SDK or Visual C++ default include) to the Path variable. e.g “C:\Program Files\Microsoft Visual Studio 8\VC\include”

5. Now you completed setting up the compiler and environment. It’s turn to build the jam source. You can locate the jam source at (Your_Boost_Root_Dir)\Tools\build\jam_src folder e.g (D:\Program Files\boost_1_33_1\tools\build\jam_src). A build.bat file will be there to build the jam source. If the visual studio 8 not existing in your build.bat file or in other words batch file is not able to take vc8 as parameter, please modify :Guess_Toolset section and :Setup_Toolset in the build.bat file. Visual C++ 7.0 Configuration will be there so you can simply copy paste and modify for Visual C++ 8.0, Just spend sometime in the batch file or download the pre-built file. :Guess_Toolset section will acn for the environment different Visual Studio Environment Variables (reverse choronological order). So it will compile with the latest version of the Visual C++ Compiler available in your system. Just give build.bat if you configured your compiler properly. See Boost Documentation for more info

6. Now you can build the libraries. the Bjam compilation will will create bin.ntx86 inside the jam_src folder. You can see the finally built bjam.exe

7. For the easy use, copy it to the boost root directory

8. You can build the boost source using following command.

For debug build:- bjam “-sBUILD=debug <runtime-link>dynamic <threading>multi” “-sTOOLS=vc-8_0″

For debug build:- bjam “-sBUILD=release <runtime-link>dynamic <threading>multi” “-sTOOLS=vc-8_0″

The -sTOOLS value also can be configured any of the following msvc, vc-7_1

Have a look at this link to know more about supported toolsets. Check about building boost under Visual C++ 8

9. The build process will create bin folder in the Boost Root directory. Each of the boost libraries will be built under seperate folder. You can do a search and put these things inside a folder for use.

I explained about the basic build processing of boost which worked out for me. Please let me know if you have some specific comments.

8 Responses to “Learning C++ 0x - Building Boost Library for Visual C++”

  1. lambert Says:

    Aaargh… Why do these “boost” people make life so complicated? It scares me that these people are on the C++ committee :(

    For crying out loud, I just need the damn libraries *compiled* on my machine, I don’t want to go through this “boost building” hell…. PLEASE don’t pollute my brain with obscure tools that I’ll probably never use again (I hope… ;)

    Life’s too short…

  2. lambert Says:

    PS: obviously this rant was aimed at the people behind Boost, not at the writer of the above article.

  3. S a r a t h Says:

    If you simply understand the logic behind the this building, it will be more easier. Initially it was painful for me. It is something linux style distribution of libraries.
    You can download the file compiled library provided by boost consulting.
    Please see my post on the same.

    http://sarathc.wordpress.com/2007/02/21/boost-library-installer-for-windows-visual-c-7180-for-linuxunix-flavors-too/

    Actually distriubting source and building it is a cool procedure. The total build will take aproximately 700 MB without building python libraries. For those who having slow net connection will not go for downloading the large large binaries as we have an option to build the same with source files. On the other hand people are not ready to crash their brain on building and learing tool for building the library. But still we can learn something from it. Also if we build the libraries, we can have our own modicifation (if any) build and use it. :)

  4. Spyros Says:

    I am not a programmer and I needed to install Boost for another library (Quantlib) to function. I have Visual C++ 2005 Express edition installed on my computer, and after some try I managed to build the library (I used the simplest command, namely /*bjam “-sTOOLS=vc-8_0″ install*/, not knowing what the other options would do). An include and a lib folder were created, and I happily added their paths to the relevant Tools->Options->Projects and Solutions->VC++ Directories using the IDE. Of course, when I attempted to compile Quantlib, the boost/config header could not be found etc..
    Perhaps I was too vain to believe that it could work with the first try, but I cannot find what is wrong and I don’t want to build again without a reason (it took something like an hour!). Any ideas?

  5. S a r a t h Says:

    Check the include order and make sure that the boost root folder is there in the include path, then only it will get include files.

  6. Lavanya Says:

    hi

    Thank for ur wonderful clear ideas regarding the installation of BOOST.
    Well, right now im trying on the installation of BOOST (as in step 8)… All the previous steps have been successfully executed.
    While compiling, in the debug built …it has skipped about 159 targets and failed to update 13 target. Im not sure wat it means… and whether the compilation is successful

    Can u throw some light in this regard
    Thanks in advance

  7. Vimal Says:

    Hi,

    I am trying to compile Boost “boost_1_33_1″ for visual studio 2005, vc8 using boost-jam-3.1.16-1-ntx86.

    I followed the steps in the tutorial above. However cannot get to generate the libraries.

    I made the following changes to build.bat
    :Guess_Toolset
    if NOT “_%VS80COMNTOOLS%_” == “__” (
    set BOOST_JAM_TOOLSET=vc8
    set BOOST_JAM_TOOLSET_ROOT=%VS90COMNTOOLS%\..\..\VC\
    goto :eof)
    setlocal & endlocal
    if NOT “_%VCINSTALLDIR%_” == “__” (
    set BOOST_JAM_TOOLSET=vc8
    set BOOST_JAM_TOOLSET_ROOT=%VCINSTALLDIR%\VC\
    goto :eof)
    setlocal & endlocal
    if EXIST “%ProgramFiles%\Microsoft Visual Studio 8\VC\VCVARSALL.BAT” (
    set BOOST_JAM_TOOLSET=vc8
    set BOOST_JAM_TOOLSET_ROOT=%ProgramFiles%\Microsoft Visual Studio 8\VC\
    goto :eof)
    setlocal & endlocal
    if EXIST “C:\Program Files\Microsoft Visual Studio 8\VC\VCVARSALL.BAT” (
    set BOOST_JAM_TOOLSET=vc8
    set BOOST_JAM_TOOLSET_ROOT=C:\Program Files\Microsoft Visual Studio 8\VC\
    goto :eof)
    setlocal & endlocal
    if EXIST “%ProgramFiles%\Microsoft Visual Studio 8\VC\VCVARSALL.BAT” (
    set BOOST_JAM_TOOLSET=vc8
    set BOOST_JAM_TOOLSET_ROOT=%ProgramFiles%\Microsoft Visual Studio 8\VC\
    goto :eof)
    setlocal & endlocal

    and later on

    :Setup_Toolset
    if “_%BOOST_JAM_TOOLSET%_” == “_msvc_” (
    if NOT “_%MSVCDir%_” == “__” (
    set BOOST_JAM_TOOLSET_ROOT=%MSVCDir%\) )
    if “_%BOOST_JAM_TOOLSET%_” == “_msvc_” (
    if EXIST “%BOOST_JAM_TOOLSET_ROOT%bin\VCVARS32.BAT” (
    call “%BOOST_JAM_TOOLSET_ROOT%bin\VCVARS32.BAT” ) )
    if “_%BOOST_JAM_TOOLSET%_” == “_msvc_” (
    if not “_%BOOST_JAM_TOOLSET_ROOT%_” == “__” (
    set PATH=%BOOST_JAM_TOOLSET_ROOT%bin;%PATH%)
    set BOOST_JAM_CC=cl /nologo /GZ /Zi /MLd -DNT -DYYDEBUG kernel32.lib advapi32.lib
    set BOOST_JAM_OPT_JAM=/Febootstrap\jam0
    set BOOST_JAM_OPT_MKJAMBASE=/Febootstrap\mkjambase0
    set BOOST_JAM_OPT_YYACC=/Febootstrap\yyacc0
    set _known_=1
    )
    if “_%BOOST_JAM_TOOLSET%_” == “_vc8_” (
    if NOT “_%MSVCDir%_” == “__” (
    set BOOST_JAM_TOOLSET_ROOT=%MSVCDir%\) )
    if “_%BOOST_JAM_TOOLSET%_” == “_vc8_” (
    if EXIST “%BOOST_JAM_TOOLSET_ROOT%bin\VCVARS32.BAT” (
    call “%BOOST_JAM_TOOLSET_ROOT%bin\VCVARS32.BAT” ) )
    if “_%BOOST_JAM_TOOLSET%_” == “_vc8_” (
    if not “_%BOOST_JAM_TOOLSET_ROOT%_” == “__” (
    set PATH=%BOOST_JAM_TOOLSET_ROOT%bin;%PATH%)
    set BOOST_JAM_CC=cl /nologo /GZ /Zi /MLd -DNT -DYYDEBUG kernel32.lib advapi32.lib
    set BOOST_JAM_OPT_JAM=/Febootstrap\jam0
    set BOOST_JAM_OPT_MKJAMBASE=/Febootstrap\mkjambase0
    set BOOST_JAM_OPT_YYACC=/Febootstrap\yyacc0
    set _known_=1
    )

    Now, when I run >bjam “-sTOOLS=vc_80″ install

    I get the following message:

    C:\Boost\boost_1_33_1>bjam “-sTOOLS=vc_80″ install
    vc_80-tools.jam: No such file or directory
    ******************************************************
    Building Boost.Iostreams with bzip2 support disabled.
    To enable bzip2, consult the Boost.Iostreams documentation
    ******************************************************
    ******************************************************
    Building Boost.Iostreams with zlib and gzip support disabled.
    To enable zlib and gzip, consult the Boost.Iostreams documentation
    ******************************************************
    Building Boost.Regex with the optional Unicode/ICU support disabled.
    Please refer to the Boost.Regex documentation for more information
    (and if you don’t know what ICU is then you probably don’t need it).
    vc_80-tools.jam: No such file or directory
    C:\Boost\boost_1_33_1\tools/build/v1\allyourbase.jam:645: in C++
    rule C++-action unknown in module
    C:\Boost\boost_1_33_1\tools/build/v1\allyourbase.jam:1142: in Object
    C:\Boost\boost_1_33_1\tools/build/v1\allyourbase.jam:1207: in Objects
    C:\Boost\boost_1_33_1\tools/build/v1\boost-base.jam:150: in dll-files
    C:\Boost\boost_1_33_1\tools/build/v1\boost-base.jam:1969: in subvariant-target
    C:\Boost\boost_1_33_1\tools/build/v1\boost-base.jam:2406: in stage
    Jamfile:224: in load-jamfiles
    C:\Boost\boost_1_33_1\tools\build\v1\bootstrap.jam:21: in boost-build
    C:\Boost\boost_1_33_1\boost-build.jam:16: in module scope

    I am obviously doing something wrong, please help.

    The similar steps worked fine and I was able to compile the libs using Visual Studio .Net 2003, but could not replicate in 2005.

    Thanks
    Vimal

  8. Vimal Says:

    Dear all,

    The problem is resolved, I used the latest 1.35 and it complies without any problem :-)

    Best regards
    Vimal

Leave a Reply