Boost Unit Test Undefined Reference

Am I missing something when I get undefined references to main using boost 1.34.1. Here is a minimal example #include <iostream> #include <boost/test/unit_test.hpp> void my_test_function() { std::cout << "hi there" << std::endl; } boost::unit_test::test_suite* init_unit_test_suite( int , char*[] ) { boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "Master test suite" ); test->add( BOOST_TEST_CASE( &my_test_function ) ); return test; } This is copied off of the main page. Here is the compilation line g++ test.cpp -o test -lboost_unit_test_framework-gcc41 With gcc version 4.1.2 Here is the error message: /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/crt1.o: In function `_start': (.text+0x18): undefined reference to `main' collect2: ld returned 1 exit status Any insight? Chris Miceli

<cmicel1@cct.lsu.edu> wrote in message news:20070825232701.1e1f7qn08wg0g4w0@webmail.cct.lsu.edu...
Am I missing something when I get undefined references to main using boost 1.34.1. Here is a minimal example
#include <iostream> #include <boost/test/unit_test.hpp>
void my_test_function() { std::cout << "hi there" << std::endl; } boost::unit_test::test_suite* init_unit_test_suite( int , char*[] ) { boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "Master test suite" ); test->add( BOOST_TEST_CASE( &my_test_function ) ); return test; }
This is copied off of the main page. Here is the compilation line g++ test.cpp -o test -lboost_unit_test_framework-gcc41 With gcc version 4.1.2 Here is the error message: /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/crt1.o: In function `_start': (.text+0x18): undefined reference to `main' collect2: ld returned 1 exit status
Any insight? Chris Miceli
This was discusedin length right after 1.34. was out. The problem essencially is that -lboost_unit_test_framework-gcc41 in your build command picks up incorrect version of the library. You should've used static version, while it picks up shared one (they both similarly, only extension is different). You've got several ways to deal with it: 1. rename shared library version of Boost.Test 2. enforce static library selection with -Bstatic and/or -Dn compiler's flags 3. Use aut registration instead combined with BOOST_TEST_MAIN/BOOST_TEST_MODULE #include <iostream> #define BOOST_TEST_MODULE my test #include <boost/test/unit_test.hpp> BOOST_AUTO_TEST_CASE( my_test_function ) { std::cout << "hi there" << std::endl; } Gennadiy
participants (2)
-
cmicel1@cct.lsu.edu
-
Gennadiy Rozental