Do i have static or dynamic boost libraries? - c++

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

Related

Avoid including path to BOOST into exe

We are working on a project written in C++ using BOOST, and the project is being built in Visual Studio. Inspecting the project build (exe file) I've discovered there is an entry of path to BOOST (on a build server). So, I guess it's there due to the __FILE__ macro.
EDIT: It's Release configuration with no debug information.
EDIT2: The following command is used for building BOOST:
b2 --toolset=msvc-10.0 --stagedir=./stage/2010/win32
address-model=32 variant=release
threading=single,multi link=static
runtime-link=static debug-symbols=off
Our customer doesn't want the path being there, so how to avoid absolute path including?
Regards,
You should use BOOST_EXCEPTION_DISABLE preprocessor definition

cmake can't find boost libraries because it looks for the wrong file names

I've built the boost (1.56) libraries on a windows (8.1) machine according to the documentation, both as shared and static libraries.
All of them appear in the BOOST_ROOT/stage/lib directory in the following file name format:
boost_thread-vc120-mt-1_56.dll
boost_thread-vc120-mt-1_56.lib
boost_thread-vc120-mt-gd-1_56.dll
boost_thread-vc120-mt-gd-1_56.lib
(this is just the thread lib, the same format is used for all the other libs as well)
When I run cmake it complains about not being able to find the boost libraries.
Running it with -DBoost_DEBUG=ON shows that it looks for different file names:
libboost_thread-vc120-mt-s-1_56;
libboost_thread-vc120-mt-s;
libboost_thread-mt-s-1_56;
libboost_thread-mt-s;
libboost_thread
I noticed the following differences:
The prefix for the actual files is boost and not libboost as cmake is searching for
The static version of the actual files just has a different file extension (.lib instead of .dll) but cmake is looking for -mt-s
Any idea how I can make cmake find the actual files without renaming the files I have to match cmake's search formats?
Thanks
Note: boost_thread-vc120-mt-1_56.lib is an import library allowing dynamic linking with boost_thread-vc120-mt-1_56.dll, while libboost_thread-vc120-mt-s-1_56 is a static library (s letter means it's also statically linked with CRT).
The application you try to build expects static Boost libraries having static CRT, so you should provide them. To build such libraries, invoke b2 with the appropriate parameters:
b2 variant=release link=static runtime-link=static stage

How to build boost required modules only?

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.

Linker error LNK1104 with 'libboost_filesystem-vc100-mt-s-1_49.lib'

During the process of linking my program to the boost::filesystem module in release mode I get the next error:
error LNK1104: cannot open file
'libboost_filesystem-vc100-mt-s-1_49.lib'
However, in the boost\stage\lib directory I only have the next libraries referred to filesystem module:
libboost_filesystem-vc100-mt-1_49.lib
libboost_filesystem-vc100-mt-gd-1_49.lib
My questions are:
Why does the VC++ is asking for 'libboost_filesystem-vc100-mt-s-1_49.lib?
Which compiler/linking properties should I change to get the compiler to ask for libboost_filesystem-vc100-mt-1_49.lib?
UPDATE: My VC2010++ solution has 2 projects that include the previous boost library: x is a library and y (the main program) which invokes to x.
When I build x with Configuration type=Static library and RuntimeLibrary=Multi-threaded (/MT), it is ok.
When I build y with Configuration type=Application (.exe) and RuntimeLibrary=Multi-threaded (/MT), it issues the error I indicated, if I change to Configuration type=Static library it builds ok, but my main program has .lib extension and not the expected .exe.
You are using /MT or /MTd option in C/C++/Code Generation/Runtime Library which require static library, boost default build with shared library output. You can switch Runtime Library to /MD or /MDd. An other option is recompile boost with static library output and you'll get 'libboost_filesystem-vc100-mt-s-1_49.lib'..
I had a similar problem with a recent project (inherited from a long legacy).
Here is a "poor man's" solution to this issue:
Rebuild the boost libraries with all variants, to be sure that you have the correct variant for your needs.
Run:
.\b2 --build-type=complete
Note that the boost build time will obviously be longer with this option.
This is not an elegant solution, but I didn't have time to mess about figuring out which exact option I needed for my project, so I just built them all.
You can paste the following characters into you control console (win+r----cmd , then go to boost src directory , find the bjam.exe)
ps:double click the bootstrap.bat can get bjam.exe
bjam --toolset=msvc-1.0 --stagedir=./lib_x64 --builddir=./ address-model=32 link=static variant=release runtime-link=static threading=multi stage debug releasde
libboost_filesystem-vc100-mt-s-1_49.lib
"link=static" correspond to -s-
"threading=multi" correspond to -mt-
"runtime-link=static" correspond to lib prefix
"variant=release" make sure libboost_filesystem-vc100-mt-s-1_49.lib don't contain -gd-
The boost libraries that you have in your boost\stage\lib directory are linking dynamically to the standard C++ libraries. See the following post:
boost lib build configuraton variations
Your code is linking statically to the standard C++ libraries, hence a mismatch. Try linking your code dynamically to the standard libraries. (Project Settings->General->Configuration Type)
run below command to rebuild boost in static in VS2013 x86 Native Tools Command Prompt.
b2 -link=static
Add your linker library paths in your project link path in VS.
Then, rebuild your project, error gone.

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