Reputation: 5648
I have this minimal unit test:
#include <boost/test/unit_test.hpp>
#define BOOST_TEST_MODULE a_test
struct Color{};
BOOST_AUTO_TEST_CASE(color_test)
{
BOOST_CHECK(std::is_pod<Color>());
}
However when I compile it like so
clang -std=c++14 -lc++ -lboost_unit_test_framework a_test.cc -o main
I get an undefined symbol for _main. -lboost_unit_test_framework
uses the shared library.
I used this library before, and I remember not having to declare a main function myself, as it was automatically running the several BOOST_AUTO_TEST_CASE
s I define.
What am I doing wrong?
Upvotes: 2
Views: 1545
Reputation: 405
@melak47 is also right. I believe the following should work, too:
#define BOOST_TEST_MODULE my_tests TestSuites // to define main()
#include <boost/test/unit_test.hpp>
struct Color{};
BOOST_AUTO_TEST_SUITE(MyColorTests)
BOOST_AUTO_TEST_CASE(color_test)
{
BOOST_CHECK( std::is_pod<Color>() );
}
BOOST_AUTO_TEST_SUITE_END()
If you link multiple such modules together, make sure that BOOST_TEST_MODULE
is only defined in one of them, before the include.
Upvotes: 0
Reputation: 4850
When linking Boost.Test dynamically, you need to define BOOST_TEST_DYN_LINK
(see boost docs here).
You may also have to link boost_test_exec_monitor
.
Also, all the configuration macros need to be defined before including the library header to have any effect.
Upvotes: 3