Compile the static Boost Libraries in Windows

From The DarkMod Wiki
Revision as of 03:23, 11 April 2019 by Stgatilov (talk | contribs) (Boost is no longer relevant.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
This article is no longer relevant: boost has been removed from TDM game in version 2.06, and removed from tdm_update in version 2.08.

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 - 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.

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), which can be built by using the boostrap.bat script found in the root boost folder. Open a Visual Studio Developer Command prompt (choose the version you want to build the libraries for, e.g. "Developer Command Prompt for VS 2017"), then run the boostrap script which will place the bjam.exe in the same folder as the bootstrap script.

Let's start compiling by using the boost.filesystem library as example. Keep using the Visual Studio Developer Command prompt:

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

Note that TDM links statically to boost, so give an additional switch runtime-link=static to bjam:

..\..\bjam toolset=msvc link=static threading=multi runtime-link=static release stage
..\..\bjam toolset=msvc link=static threading=multi runtime-link=static 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 the build folder (the one you launched the bjam command in). 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). This argument is usually not necessary if you're using the correct VS command prompt.

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

Building boost.python

I found it's possible to have both the x86 and x64 variants of Python around on your system to compile the boost.python library for both 32 and 64 bit platforms. Get the x86 and x64 installer from the Python website and install them into separate target folders. I tried this with Python 3.6, so your mileage might vary.

Create a user-config.jam file and put it into your user folder, that might be C:\Users\greebo, for instance. To compile the 32-bit boost.python libs, I used the user-config.jam below, with my Python 3.6 x86 installation sitting in D:\temp\Python36-32 (for the records, I did not let the Python installer add anything to the PATH environment variable):

using python 
    : 3.6                   # Version
    : D:\\temp\\Python36-32\\python.exe      # Python Path
    : D:\\temp\\Python36-32\\include         # include path
    : D:\\temp\\Python36-32\\libs            # lib path(s)
    : <define>BOOST_ALL_NO_LIB=1
    ;

The I opened the Visual Studio Developer Command Prompt, changed folder to where I extracted the boost package (e.g. d:\temp\boost1_64) and started building using this command:

b2.exe toolset=msvc variant=release,debug link=static threading=multi stage --with-python

This will place the 32-bit libraries in the stage folder, where you can pick them up. Boost will create variants with "python" as well as "python3" in their name, I found it's only necessary to copy the "python" ones.

Note: you can try adding the switch --debug-configuration to your b2 command line to see some info about what Python folder b2 is linking against.

For the x64 build, the user-config.jam is the same except for the different paths. I cleared up the bin.v2 folder before starting the build, otherwise b2 would refuse to build anything, thinking everything was up to date:

using python 
    : 3.6                   # Version
    : D:\\temp\\Python36-64\\python.exe      # Python Path
    : D:\\temp\\Python36-64\\include         # include path
    : D:\\temp\\Python36-64\\libs            # lib path(s)
    : <define>BOOST_ALL_NO_LIB=1
    ;

The b2 command line I ended up using was this:

b2.exe toolset=msvc variant=release,debug link=static threading=multi stage --with-python address-model=64

which placed the generated libraries in the stage folder just as above.

Boost.CMake

Some people find bjam to be extremely problematic under Windows. If you are having trouble, I would suggest trying the CMake build system branch of Boost. This is also very helpful with compiling the libs for use with Intel's compilers which tend to be badly supported by the bjam build system. Another advantage is that CMake generates Visual Studio solution files, meaning that you can adjust build settings or rebuild components with a familiar interface.

CMake in Windows has a nice GUI which makes configuring the build very easy, as well as providing a way to easily adjust them at a later stage.

Boost.Cmake - Boost Wiki - Boost.Cmake - Gitorious

Steps

CMake:

  1. Download the latest binary release of CMake for your platform CMake and related downloads
  2. Install it. Make sure that the CMake GUI gets installed.

Boost.CMake Source:

  1. Figure out which release of Boost that you need — in this case we will assume 1.45.
  2. Download the relevant release tarball from the Gitorious branch (or use git/hg-git). The tarball can be found in the branch overview i.e, : Boost.CMake 1.45 branch
  3. Unpack the tarball somewhere.

Configuration and Generating:

  1. Run the CMake GUI tool.
  2. Set the source path to the location where you unpacked the tarball.
  3. Set an (empty) build directory - Note: while it says that this is where the binaries will be placed, this is actually going to be where all of the temporary build files are located, it will also contain the libs if we use default paths - don't freak out if there's loads of other stuff.
  4. Click 'Configure' and set set which toolset/compiler you will be using. Note: If you are using icc, you will want to use Visual Studio as the generator but specify the compilers manually (icl.exe).
  5. There should now be a grid of default build options, many in red. Adjust them if needed, make sure that ENABLE_STATIC, ENABLE_MULTI_THREADED and ENABLE_RELEASE are ticked.
  6. Once the configure process is complete, click 'Generate' - This will now place the solution file into the build directory.

Building:

  1. Go to the build directory, as specified above.
  2. Open the solution file.
  3. Note: By default the libraries are built as multithreaded-dll's (/MD flag) this needs to be changed to normal multithreaded for use with TDM. If you are having trouble with TDM linking looking in some strange libs/dlls, this is why.
    1. Select all of the projects that you wish to build, then right click on them in the solution browser and go to 'Properties'.
    2. Expand the C++ tab => Code Generation => Runtime Library, change this to 'Multi-threaded (/MT).
    3. Apply.
  4. While they are still selected, right click on them and then build them.

You should now have the .libs in a /lib folder within your working directory. The libs might need renaming to fit with the naming scheme that is expected, e.g, : boost-regex-intel-mt-1_45.lib => libboost-regex-iw-mt-s-1_45.lib. This could likely be fixed in the CMakeLists file if you wanted, as well as the /MD -> /MT switch.