From c0d59b6849b1c01cda9f7735dbadfabc83d111c1 Mon Sep 17 00:00:00 2001
From: John Maddock
The Jamfile for building library "whatever" typically lives in - boost-root/libs/whatever/build, start by defining the project root for the - Jamfile:
-subproject libs/whatever/build ;-
Then add the static library build target (if supported):
-lib - boost_whatever - : # list all the sources for this - library: - ../src/whatever.cpp - : # all build requirements go - here. # the "common-variant-tag" rule ensures that the library will - # be named according to the rules used by the install - # and auto-link features: - common-variant-tag - # set include path for Boost headers: - <sysinclude>$(BOOST_ROOT) - : - # list default build variants here - debug release - ;-
Then add the dll build target (if supported). In this case the build - requirements section get an extra define: so that our sources know to export - their own symbols (and import those from any other boost libs on which we may - be dependent). We also restict shared library builds to dynamic-runtime - build variants, if we don't do this then dll's linked against static runtimes - are unlikely to function correctly (the dll will have a separate runtime from - the executable using it, this generally causing problems with new and - delete, as well as exception handling runtimes).
-dll - boost_whatever - : # list all the sources for this - library: - ../src/whatever.cpp - : # all build requirements go - here. # the "common-variant-tag" rule ensures that the library will - # be named according to the rules used by the install - # and auto-link features: - common-variant-tag - # tell our source that we're building (and maybe using) dll's: - <define>BOOST_ALL_DYN_LINK=1 - # only build this for dynamic runtimes: - <runtime-link>dynamic - # set include path for Boost headers: - <sysinclude>$(BOOST_ROOT) - : - # list default build variants here - debug release - ; --
Now add an install target so that Boost.Install can find this library to - install:
-install whatever lib - : <dll>boost_whatever <lib>boost_whatever - ; --
Finally add a stage target that will copy the built libraries to a common - sub-directory (boost-root/stage/lib):
-stage stage/lib : <lib>boost_whatever <dll>boost_whatever - : - # copy to a path rooted at BOOST_ROOT: - <locate>$(BOOST_ROOT) - # make sure the names of the libraries are correctly named: - common-variant-tag - # add this target to the "stage" and "all" psuedo-targets: - <target>stage - <target>all - : - debug release - ; -+ boost-root/libs/whatever/build, the only extra step required is to add a + <define> requirement to the library target so that your code knows + whether it's building a dll or static library, a typical Jamfile would like + like this: +
+lib boost_regex : ../src/whatever.cpp : + <link>shared:<define>BOOST_WHATEVER_DYN_LINK=1 ; +
Testing the auto-link feature reasonable straightforward using - the Boost.build system: we need to build the "whatever" library's test - files without explicitly specifying the library to link to in the Jamfile, for - example:
-subproject libs/whatever/test/auto-link-test ; - -# bring in the rules for testing -import testing ; - -# start with a static linking version: - -run - # sources - ../whatever_test.cpp - : - : # input files - : # requirements - <library-path>../../../../stage/lib - <define>BOOST_LIB_DIAGNOSTIC=1 - : # program name - whatever_test - ; - - # and then a dll linking version: - run - # sources - ../whatever_test.cpp - : - : # input files - : # requirements - <library-path>../../../../stage/lib - <define>BOOST_LIB_DIAGNOSTIC=1 - <define>BOOST_ALL_DYN_LINK=1 - <runtime-link>dynamic - : # program name - whatever_test_dll - ; - --
Please note however that this Jamfile will only build with compilers that do - actually support auto-linking, so it should not be added to the regular - regression tests. The Jamfile should also be built for all possible build - variants, for the Microsoft / Borland compilers that means doing a:
-bjam -sBUILD="release debug <threading>multi/single <runtime-link>static/dynamic" test -+
Testing the auto-link feature is somewhat convoluted, and requires access + to a compiler that supports the feature: refer to + libs/config/test/link/test/Jamfile.v2 for an example.
Revised @@ -487,4 +383,3 @@ run attribution then please provide a link to this article.