Compile the static Boost Libraries in Windows: Difference between revisions

From The DarkMod Wiki
Jump to navigationJump to search
New page: There are several methods to obtain Boost binaries for Windows build environments. The boost static libraries follow a naming convention as explained in the boost online docs: http://www...
 
Line 24: Line 24:
After these commands are done, the '''libboost_filesystem_vc*.lib''' files (both debug and release variants) can be found in the '''stage/''' directory below your boost folder. You'll need to repeat the above steps and replace '''filesystem''' with the names of the other libraries, e.g. '''regex''', '''thread''' or '''system'''.
After these commands are done, the '''libboost_filesystem_vc*.lib''' files (both debug and release variants) can be found in the '''stage/''' directory below your boost folder. You'll need to repeat the above steps and replace '''filesystem''' with the names of the other libraries, e.g. '''regex''', '''thread''' or '''system'''.


Note for x64 users: Add the <tt>address-model=64</tt> option to bjam (after the threading argument) in order to build static libs with the 64-bit compiler.
* Note for x64 users: Add the <tt>address-model=64</tt> option to bjam (after the threading argument) in order to build static libs with the 64-bit compiler.
Note for users with multiple versions of Visual Studio: you can specify exactly which toolset you want to use by setting <tt>toolset=msvc-9.0</tt> (for VC++ 2008) and <tt>toolset=msvc-10.0</tt> (for VC++ 2010).
* Note for users with multiple versions of Visual Studio: you can specify exactly which toolset you want to use by setting <tt>toolset=msvc-9.0</tt> (for VC++ 2008) and <tt>toolset=msvc-10.0</tt> (for VC++ 2010).


Now take the *.lib files from the stage/ folder and copy them into your project's library folder and the linking should succeed.
Now take the *.lib files from the stage/ folder and copy them into your project's library folder and the linking should succeed.

Revision as of 08:33, 5 December 2010

There are several methods to obtain Boost binaries for Windows build environments.

The boost static libraries follow a naming convention as explained in the boost online docs: http://www.boost.org/doc/libs/1_45_0/more/getting_started/windows.html#library-naming When including boost headers in your MSVC++ projects, the headers (like <boost/regex.hpp>) make use of VC's auto linking feature, so you don't need to worry about the actual file names, the linker is automatically instructed to require the correct libraries. All you have to do is make sure the linker can find these files in your project's libs directory.

Download them from sourceforge

You can try to find the static binaries needed on boost's sourceforge page: http://sourceforge.net/projects/boost/files/boost-binaries/

Often for very "fresh" releases there are no binaries available yet, so you'll need to fall back compiling the binaries yourself.

Compile the libraries from Boost sources

Download the boost release package from their website, e.g. Boost 1.45, and extract it to a folder. For this guide, I'll assume your boost package has been saved to c:\tools\boost_1_45_0).

To build the static libraries Boost you need the the boost jam tool (bjam.exe). At the time of this writing there is a precompiled bjam.exe availabe on sourceforge. Save the bjam.exe into some place you remember (e.g. c:\tools\bjam.exe). In case the bjam.exe can not be found, you can also build it from sources (this is not within the scope of this article).

Let's start compiling by using the boost.filesystem library as example. Open a command console (Win-R ==> "cmd" => Enter).

cd c:\tools\boost_1_45_0
cd libs
cd filesystem
cd build
c:\tools\bjam toolset=msvc link=static threading=multi release stage
c:\tools\bjam toolset=msvc link=static threading=multi debug stage

After these commands are done, the libboost_filesystem_vc*.lib files (both debug and release variants) can be found in the stage/ directory below your boost folder. You'll need to repeat the above steps and replace filesystem with the names of the other libraries, e.g. regex, thread or system.

  • Note for x64 users: Add the address-model=64 option to bjam (after the threading argument) in order to build static libs with the 64-bit compiler.
  • Note for users with multiple versions of Visual Studio: you can specify exactly which toolset you want to use by setting toolset=msvc-9.0 (for VC++ 2008) and toolset=msvc-10.0 (for VC++ 2010).

Now take the *.lib files from the stage/ folder and copy them into your project's library folder and the linking should succeed.

Boost.Python

To compile the Boost.Python static lib, you'll need to have a Python distribution installed in your system, otherwise bjam will complain that no Python installation can be found. Download a package from the Python website and install it.

Note: the boost python static library (e.g. libboost_python-vc100-mt-gd-1_42.lib) will contain a reference to a specific version of the python static library. If you downloaded Python 2.7.1, your boost static lib will contain a reference to python27.lib. This file can be found in the libs/ in the directory you installed Python to, you should add that file to your project's library directory as well.

Another note: when linking against that python27.lib your application will require the python27.dll at runtime. This file can be somewhat tricky to locate. For 32 bit systems this is usually C:\Windows\system32, for x64 systems the 32 bit Python DLL can be found in your C:\Windows\SysWoW64\ folder. On x64 systems, the 64 bit Python DLL is right in C:\Windows\System32.