Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Customizing the module's entry point

In the static library variant, customizing the main entry point is quite troublesome, because the definition of function main is already compiled into the static library. This requires you to rebuild the Unit Test Framework static library with the defined symbol BOOST_TEST_NO_MAIN. In the Boost root directory you need to invoke command

> b2 --with-test link=static define=BOOST_TEST_NO_MAIN define=BOOST_TEST_ALTERNATIVE_INIT_API install
[Warning] Warning

This removal of entry point definition from the static library will affect everybody else who is linking against the library. It may be less intrusive to switch to the shared library usage variant instead.

In one of the source files, you now have to define your custom entry point, and invoke the default test runner unit_test_main manually with the default initialization function init_unit_test as the first argument. There is no need to define BOOST_TEST_NO_MAIN in your source code, but you need to define BOOST_TEST_ALTERNATIVE_INIT_API in the main file:

In exactly one file

In all other files

#define BOOST_TEST_MODULE test module name
#define BOOST_TEST_ALTERNATIVE_INIT_API
#include <boost/test/unit_test.hpp>

// entry point:
int main(int argc, char* argv[], char* envp[])
{
  return utf::unit_test_main(init_unit_test, argc, argv);
}
#include <boost/test/unit_test.hpp>

//
// test cases
//

//
// test cases
//
[Note] Note

The reason for defining BOOST_TEST_ALTERNATIVE_INIT_API is described here.


PrevUpHomeNext