How to build boost required modules only? - c++

I just started compiling boost C++ libraries. With the following commands I issued it is building whole of the boost libraries, which is time consuming, and is not necessary for my need.
Just unpacked the boost_1_49_0.7z archive and from Visual Studio 2010 command line tool I ran bootstrap.bat and it created the b2 executable.
Using this executable I ran b2 --toolset=msvc-10.0 --build-type=complete architecture=x86 address-model=64 stage to build the libraries.
At this moment all I need is the "signals" module to be built.
What switch commands need to be supplied to the bootstrap created executable to compile and build only those specific libraries?

b2.exe --help outputs the following.
--show-libraries Displays the list of Boost libraries that require
build and installation steps, then exit.
--with-<library> Build and install the specified <library>
If this option is used, only libraries
specified using this option will be built.
Also is possible to use the -jX option to compile BOOST in X processes in parallel.

Related

What is a staged boost library?

While trying to build the thrift c++ library, I came across the following error after specifying the --with-boost option.
If you have a staged boost library (still not installed) please
specify $BOOST_ROOT in your environment and do not give a PATH to
--with-boost option.
I looked through the boost documentation (which is I am not overly familiar with), but I did not find a good definition for the term staged boost library. I see the parenthetical (still not installed), but there are many states that are a library can be in that fall under the category of not installed.
When I first download boost, I run ./bootstrap and ./b2 to compile it.
Is it staged at this point? Or do I have to do something else to make it staged?
You can call
b2 --help
to see options of Boost.Build, and there you can find
install Install headers and compiled library files to the
======= configured locations (below).
...
stage Build and install only compiled library files to the
===== stage directory.
The declaration of stage or install specifies whether the Boost Libraries are installed in a subfolder named stage or system-wide. The meaning of system-wide depends on the operating system. In Windows, the target directory is c:\boost, in Linux it is /usr/local. The target directory can also be explicitly specified using the -–prefix option. Also see this answer, I guess it will be helpful.
For more informations see Getting Started Guide for Windows or Linux.
When you run .\b2 to compile Boost, it create a folder called stage and output of the compilation is put inside %BOOST_ROOT%\stage\lib folder. Now you can copy this lib folder somewhere and add that in to linker's path. However some projects might expect binaries to be available at stage\lib. So "staged" here means if you have libraries compiled and present in stage\lib folder. The .b2 command takes several different parameters to compile different kids of binaries, for example, below compiles binaries that are linked to shared runtime and targeting x64 architecture:
b2 variant=debug,release link=shared runtime-link=shared address-model=64
Each variant of lib file name has tags so they don't overwrite each other, for example, libboost_date_time-vc140-mt-gd-1_62.lib.

What's the difference between b2 and ./bootstrap.sh when building python

Sorry if this has already been asked? I've build boost from source but have always been confused about the build tools. Which tool should be used when building the boost libraries from scratch. To me it seems that bootstrap.sh is used to create the bjam executable and then bjam should be used to do the actual build. However, I've noticed that you can pass lots of parameters to bootstrap.sh such as the toolset (compiler) to use and the libraries to build, etc...and launch the build with bootstrap.sh
Also, there are at least three different ways of starting a build: ./bootstrap.sh, bjam, b2
Could someone summarize the purpose of each as the online docs don't seem to explain this
Thanks!
Anwar
b2 is just the second version of bjam. The bootstrap.sh script just builds the boost jam executable from the source code contained in the boost source, creates project-config.jam and executes the executable. You can see the shell script here

Do i have static or dynamic boost libraries?

I have ran bjam.exe --build-dir="C:\build-boost" --build-type=minimal msvc stage
and now I have libraries .lib with these headers, for example
libboost_serialization-vc100-mt
libboost_serialization-vc100-mt-1_45
libboost_serialization-vc100-mt-gd
libboost_serialization-vc100-mt-gd-1_45
I believe these should be static libraries for debug and release version. When I run the compiler with Multi-threaded Debug (/MTd) it gives an error LNK1104: cannot open file 'libboost_serialization-vc100-mt-sgd-1_45.lib' It is looking for one with -sgd
where am i going wrong?
Something that is kind of confusing is there are two 'static' options for building boost with MSVC.
B2.exe takes the option link=static which tells boost that you want to link it (boost) statically. If you are compiling your VC project with /MT or /MTd you will also need to use the runtime-link=static option to tell boost that you will be linking to the VC runtime libraries statically.
It is the second runtime-link=static which puts the -s in the .lib name.
My command line for building boost was
b2.exe --toolset=msvc variant=release link=static threading=multi runtime-link=static stage
You have the dynamic versions. The static ones are delimited by having the "s" in the name. Make sure you specified link=static on the bjam command line. If not, you'll have to rebuild to make the static versions.
See Boost getting started windows section 6.3 naming and section 6.1 on Unix naming
For static libraries there should be a s in there e.g. -sgd so you have dynamic libraries
here is how i break it down
libboost_serialization-vc100-mt-sgd-1_45.lib
lib- if boost library starts with lib then its a static library , shared library do not start with lib prefix. Also static library will have a '-s' in the name.
mt- multi-threaded , obtained by specifying threading=multi when you ran bjam or b2.This is the default threading.
g- use debug libraries for building the code
d- build a debug version of your code
So your compiler is searching for multi-threaded static debug library(mt-sgd) as you ran with /MTd(Creates a debug multithreaded executable file using LIBCMTD.lib). I guess by default it must be searching for static library. If you want a dynamic library, insert these lines in your code or define a macro
#define BOOST_ALL_DYN_LINK
Please check this document:
http://www.boost.org/doc/libs/1_45_0/more/getting_started/windows.html#library-naming
There you can find the meanings of all letters and how you can build the boost accordingly also...

Boost libraries - build only what I need

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?
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
These answers didn't work for me. On Windows, this worked for me:
b2.exe --with-LIBRARY
For example,
b2.exe --with-test
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.
I had the same problem. But I found a way to create the necessary files.
Steps to follow:
If you have Microsoft Visual Studio 2010 then open the Microsoft Visual Studio command prompt (2010) in administrator mode.
First enter the code:
bootstrap.bat
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
Library files will be created in stage folder.
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.
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).

Building Boost for static linking (MinGW)

I'm building Boost (I'm using System and FileSystem) for MinGW using bjam:
bjam --toolset=gcc stage
And it builds fine, but I want to be able to statically link to it (I have to have a single file for the final product) so I tried:
bjam --link=static --toolset=gcc stage
But I get the same output. Any ideas?
edit second question in a row I've answered moments after posting :p guess I'll leave this up here for others though.
bjam --build-type=complete --toolset=gcc stage
Will build both dynamic and static for sure.
I think link is a property as opposed to an option for bjam. That means that there should be no -- before it.
This is my command line for building only static libraries (visual c++ though):
bjam install --toolset=msvc variant=release link=static threading=multi runtime-link=static
Mapping that to your original build command I would say it should look something like this:
bjam --toolset=gcc link=static stage
or perhaps:
bjam stage --toolset=gcc link=static
Try running
bjam --help
for more info on properties and options for bjam.
Just want note that with the newer boost (Feb 2011) you need to build bjam as well now.. for some reason the current downloadable bjam doesn't work cleanly.
So first:
cd ...\boost_1_45_0\tools\build\v2\engine\src
build.bat mingw
Youll need to add bjam to the PATH (from control panel, not just on the cmd prompt). Then
cd ...\boost_1_45_0\
bjam --build-type=complete --toolset=gcc stage
My setup is Vista, Boost 1.45, MinGW 4.5, and building from cmd.exe not msys.
http://code-slim-jim.blogspot.com/2011/02/boost-in-vista-using-mingw-and-cmdexe.html
I have not built this myself in MinGW but I believe your first build will output both dynamic and static libraries and the second only static ones, so if you did not clean the build directories in between builds it will probably look the same.
When you write "I have to have a single file..." do you mean you need a single library containing all boost libraries? If so, I suspect you may have to 'ar' them together yourself.
I use the following command line to build both the statically linked as well as the dynamically linked versions of boost:
bjam "-sBUILD=debug release <runtime-link>static/dynamic <threading>multi" stage
This is done with visual c++ on windows YMMV.