Boost logo

Boost Users :

Subject: [Boost-users] Boost.Test with a static library
From: Moritz Beber (moritz.beber_at_[hidden])
Date: 2008-11-21 02:47:09


Hello everyone,
after prying for any hints in the documentation and reading frustrating
mails in the archives for a while now, I get the feeling that this is a
very confusing topic.
My aim is to use a static library of boost.test because I need to
compile it a lot and the waiting time when using the header is just
frustrating.
So I added to the "Jamfile.v2" in "libs/test/build" under "requirements"
the following line:
<define>BOOST_TEST_ALTERNATIVE_INIT_API=1

Then I used boost.build and apart from a few warnings like:
./boost/test/detail/config.hpp:85:1: warning:
"BOOST_TEST_ALTERNATIVE_INIT_API" redefined
<command-line>: warning: this is the location of the previous definition
everything seemed alright. So I'm assuming I now have a static library
with this macro defined so it should use the alternative initialiser.

Then I tried the following code, which I mostly copied from the
documentation, except for adding two macros:

#define BOOST_TEST_NO_LIB
#define BOOST_TEST_ALTERNATIVE_INIT_API
#define BOOST_TEST_MODULE example
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE( test_suite1 )

BOOST_AUTO_TEST_CASE( test_case1 )
{
    BOOST_WARN( sizeof(int) < 4 );
}

BOOST_AUTO_TEST_CASE( test_case2 )
{
    BOOST_REQUIRE_EQUAL( 1, 2 );
    BOOST_FAIL( "Should never reach this line" );
}

BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE( test_suite2 )

BOOST_AUTO_TEST_CASE( test_case3 )
{
    BOOST_CHECK( true );
}

BOOST_AUTO_TEST_CASE( test_case4 )
{
    BOOST_CHECK( false );
}

BOOST_AUTO_TEST_SUITE_END()

When I try to compile, however, I get the following error:

/home/engineer/libs/boost/lib/libboost_unit_test_framework-gcc43-mt-1_37.a(unit_test_main.o): In function `main':
unit_test_main.cpp:(.text+0x2229): undefined reference to
`init_unit_test()'
collect2: ld returned 1 exit status

Which I thought the macro BOOST_TEST_MODULE would take care of. I also
tried using the BOOST_TEST_MAIN and took out the BOOST_TEST_NO_LIB.
Nothing made a change to the compiler error.

Can anyone help? Or give me a link to some proper documentation of how
to resolve this issue?
Thanks,
Moritz


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net