Boost.Test linker error - undefined reference to 'main'

Bug #162155 reported by Jestine Paul
2
Affects Status Importance Assigned to Milestone
boost (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

 I get the following error while linking with libboost_unit_test_framework.

user23@Mycomp:~/scrapbook$ g++ unit_test_example1.cpp -lboost_unit_test_framework
/usr/lib/gcc/i486-linux-gnu/4.1.3/../../../../lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status

I am using this example http://beta.boost.org/doc/libs/1_33_1/libs/test/example/unit_test_example1.cpp

But, it works fine while linking with the static library using the following command.
      g++ test3.cpp /usr/lib/libboost_unit_test_framework.a

unit_test_example1.cpp :-
// Boost.Test
#include <boost/test/unit_test.hpp>
using boost::unit_test::test_suite;

// most frequently you implement test cases as a free functions
void free_test_function()
{
    // reports 'error in "free_test_function": test 2 == 1 failed'
    BOOST_CHECK(2 == 1); // non-critical test => continue after failure

    int* p = (int*)0;
    *p = 0;
}

test_suite*
init_unit_test_suite( int, char* [] ) {
    test_suite* test= BOOST_TEST_SUITE( "Unit test example 1" );

    // this example will pass cause we know ahead of time number of expected failures
    test->add( BOOST_TEST_CASE( &free_test_function ), 1 /* expected one error */ );

    return test;
}

// EOF

Revision history for this message
Guido U. Draheim 2007 (guidod-2007-) wrote :

The boost documentation is outdated. Please read
    /usr/include/boost/test/unit_test.hpp
which defines "main" (i.e. it is not a real symbol in the lib*.so).
You will find the requirement for two precompiler defines
   if defined(BOOST_TEST_DYN_LINK) && defined(BOOST_TEST_MAIN)

Note: earlier boost libraries did not require those defines,
and I did only came across this as ALL my programs did
not compile anymore after upgrading the operating system.
(actually to Ubuntu 08.04 w/ boost 1.34.1).

However, blame the boost developers, not the packagers.

Daniel T Chen (crimsun)
Changed in boost:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.