Search code examples
c++boostbjam

Boost bjam Jamfile import statement


I have a complex C++ application that is building via bjam (V2) utility (along with some shellscripts to bootstrap the environment)

In the Jamroot file , there are "include(s)" , some of which are documented as builtin , but a lot look like "custom" stuff.

I'm trying to add unit tests and I am having difficulty understanding the lifecycle of what bjam is actually doing. The official error is that the linker is failing to "find" libraries that really should be visible , bc they're used at compile time and I do see "mention" of them in Jamroot. Soo I'm not sure if I need to explicitly declare something in the unit-test target to nudge it or what? Do i have to follow some special "order" ? Does anybody have any expirience with this? Basically i have a bunch of unittest_someclass.cpp files in same dir where my code is and i want them to compile/run as part of the build. Each test has own main function that will setup and run the tests.

I thought all i had to do was import test; and all requirements would be inherited from parent Jamroot, but looks like this is not the case?

Boost version is 1.53

Here's a code sample of what I added in Jamfile

 custom_lib_target my_project_lib
     :
   /boost//headers
   /some_other_stuff//etc
   ...
     :
    <warn_extra>off
    ...etc...
     ;

   #my unit_test target 
 exe boost_tester
   :
  my_project_lib
   ;

 unit-test test_all
 : [ glob unittest*.cpp ] boost_tester
 ;     

Solution

  • So the issue was not so much with boost test framework (although this could be better documented) , the problem was with the linker not being able to find debug variants of various libraries to link against. (Reading the warnings helped.) So while the build worked for the project when run from root , it failed for sub-projects, for example while trying to run unit tests individually. I was able to fix it by hardcoding (not ideal but it works) the paths to debug variants as follows:

    lib my_lib : : <file>/path/to/my_lib-d.so <variant>debug

    Then you use it in your test build like so

    unit-test my_test : [ glob unittest*.cpp ] my_lib : ;

    I'm not familiar enough with Boost.Build V2 at this point, so I don't know how to make this more "elegant"