Boost logo

Boost Users :

From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2007-04-30 12:19:53

Hi, Chris

1.34. version of Boost.Test made changes in design of the dynamic library
based version of the UTF. Since there is no way to portably place function
main() in shared library, it had to be moved into the header. You've got 3

1. Switch to the static library variant of the UTF. No changes required in
your test module.
2. Use the automated registration facilities and define the macro
BOOST_TEST_MAIN/BOOST_TEST_MODULE before boost/test/unit_test.hpp inclusion.
In this case both function main() and an empty test module initialization
function are generated as part of your test file automatically.
3. If you prefer to keep manually registered test cases and/or need to
perform custom test module initialization you will have to comply to the an
alternative initialization function signature and implement function main()
yourself as direct forward to the test runner supplied with dynamic library
variant of the UTF:

bool your_init_func()
    // do you initialization here
    // register you test cases in master test suite:
    // framework::master_test_suite.add( ... );

    return true; // true - init successful, false - otherwise

main( int argc, char* argv[] )
    return ::boost::unit_test::unit_test_main( &your_init_func, argc,
argv );

In both cases 2 and 3 you need to define BOOST_TEST_DYN_LINK. I personally
recommend you to consider option 2. You will soon find it much easier to
manage and write new test module.



"Chris Fairles" <chris.fairles_at_[hidden]> wrote in message
> Testing out boost beta 1.34. I built the whole she-bang with the gcc
> toolset. I tried compling my unit tests and they all get:
> /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../lib64/crt1.o: In
> function `_start':
> (.text+0x20): undefined reference to `main'
> collect2: ld returned 1 exit status
> I don't use the auto test case mechanism. My tests suites look like:
> #include "boost/test/unit_test.hpp"
> using boost::unit_test::test_suite;
> void free_test_function() {
> BOOST_CHECK(1 == 1);
> }
> test_suite*
> init_unit_test_suite( int, char* [] ) {
> test_suite* test= BOOST_TEST_SUITE( "Unit test example 1" );
> test->add( BOOST_TEST_CASE( &free_test_function ) );
> return test;
> }
> I compile using g++ -Wall -I/usr/local/include/boost-1.34 -o
> unit_test unit_test_test.cpp -L/usr/local/lib64
> -lboost_unit_test_framework-gcc41-mt-d
> If i define BOOST_TEST_DYN_LINK either in the cpp file before or after
> the unit_test.hpp include, or specifify it using -D on the command
> line I get the same results.
> I tried to look through the headers responsible for defining
> BOOST_TEST_DYN_LINK but theres a lot of references to "msvc
> auto-linking" which I of course do not use. Should I be defining
> BOOST_ALL_DYN_LINK ? I recall it not being set somewhere because
> v2 doesn't like it or something.
> Really i can't make heads or tails of what I should be defining,
> whether I shouldve defined something when building the unit test libs,
> or whether I should be defining something building my own. The docs
> say something about defining BOOST_TEST_DYN_LINK but as stated above,
> it doesn't seem to make a difference.
> Chris

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at