I'm using Boost.Test for unit testing.
Because of several reasons, I would like to write the unit test cases on different static libraries.
The problem is that when I do this, the automatic registrar doesn't work.
For instance, if I have something like:
// foo_tests.cpp
#define BOOST_TEST_MODULE "Foo"
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE( Bar )
{
BOOST_CHECK( false );
}
// used to generate libFooTests.a
// main.cpp
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
// used to generate main.o
Then, if I link main.o with libFooTests.a and execute the final binary, it says:
Test setup error: test tree is empty
Everything works just fine if I create the binary from the source codes directly, but I wan't to be able to write unit tests inside static libraries using automatic registration.
Can I achieve this?
Is there some macro I need to define? Some symbol that I need to export from libFo开发者_StackOverflow社区oTests.a?
Thanks!
How to force inclusion of "unused" object definitions in a library
That's your same problem and you'll have to derive a solution similar to what I did in my answer.
精彩评论