Boost libraries - build only what I need

C++Boost

C++ Problem Overview


I downloaded the Boost libraries and now I want to build only a few of the libraries. What would be the right command for this? Apparently the build-type=complete option gives me too much. I am using Windows XP and want to use Bjam to compile Boost and MinGW to finally use it. At the moment I think I need the libraries Boost.filesystem, Boost.ProgramOptions and Boost.System.

Another question: Where do I put the header-only libraries?

C++ Solutions


Solution 1 - C++

In step 5.2.4 of Getting Started you can instruct b2 which libraries to build:

./b2 --with-program_options --with-filesystem --with-system

Alternatively, use ./b2 --show-libraries to see a list of all libraries that are not header-only.

Following is an excerpt from the page: >In particular, to limit the amount of time spent building, you may be interested in: > > - reviewing the list of library names with --show-libraries > - limiting which libraries get built with the --with-<library-name> or --without-<library-name> options > - choosing a specific build variant by adding release or debug to the command line.

Note: b2 command depends upon boost version so use following commands as per your boost version(Also, in this case use --with-libraries=<comma-seperated-library-names> version instead of --with-<library-name>):

  • ./configure for 1.38.0 and earlier
  • ./bootstrap.sh for 1.39.0 onwards till 1.46.0

Solution 2 - C++

These answers didn't work for me. On Windows, this worked for me:

b2.exe --with-LIBRARY

For example,

b2.exe --with-test

Solution 3 - C++

The BCP utility is a tool for extracting subsets of Boost. It's useful for Boost authors who want to distribute their library separately from Boost, and for Boost users who want to distribute a subset of Boost with their application.

The current version of Boost (1.50.0) uses Boost.Build. The new workflow for building BCP is as follows:

From the root Boost directory, type:

bootstrap.bat

Then, once Boost.Build has been built, type:

b2 tools/bcp

To extract, for example interprocess only, you could use:

$ mkdir /tmp/interprocess #bcp needs this
$ bcp interprocess /tmp/interprocess

This copies interprocess and its dependencies to /tmp/interprocess.

Solution 4 - C++

I had the same problem. But I found a way to create the necessary files.

Steps to follow:

  1. If you have Microsoft Visual Studio 2010 then open the Microsoft Visual Studio command prompt (2010) in administrator mode.

  2. First enter the code:

    bootstrap.bat
    
  3. Then enter the following code to generate lib files:

    b2.exe link=static runtime-link=static --with-chrono --with-date_time --with-filesystem --with-program_options --with-system --toolset=msvc-10.0 define=BOOST_USE_WINAPI_VERSION=0x0500
    
  4. Library files will be created in stage folder.

Solution 5 - C++

My last build attempt for the Boost 1.55 libraries was a dissappointment. All attempts to build several libraries and only them has ended up with total mess in output.

BJam either tries to build everything or build only the requested, but in the "bin.v2/[long-random-path]" folders (library per directory) with crap in them which is a headache to copy only the link libraries to somethere else.

I have accidentally found the right way to build-and-collect only the libraries I want in one place without any other crap:

> bjam ... --with-[library1] --with-[library2] stage

  • the "stage" option is required to build and collect libraries in one folder: /stage/lib
  • the "--with-[library]" option is required to build only the library you want.

Solution 6 - C++

An additional note for anyone who sees the error message: "error: wrong library name '<name of library>' in the --with-<library> option.".

If you try to be clever, as I did, and only extract the boost sub-directory of the download onto your system to minimise space, b2 will not be able to find the source code and build options for those libraries that are not header-only. I.e. you need the lib sub-directory too (and tools).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTill BView Question on Stackoverflow
Solution 1 - C++Sam MillerView Answer on Stackoverflow
Solution 2 - C++CookieView Answer on Stackoverflow
Solution 3 - C++Haiyang XuView Answer on Stackoverflow
Solution 4 - C++Arun kumar KalaiarasanView Answer on Stackoverflow
Solution 5 - C++AndryView Answer on Stackoverflow
Solution 6 - C++stanthomasView Answer on Stackoverflow