2

I am trying to compile an example from boost::test tutorial:

#include <boost/test/included/unit_test.hpp>
using namespace boost::unit_test;

void test_case1() { /* : */ }

test_suite*
init_unit_test_suite( int argc, char* argv[] )
{
  test_suite* ts1 = BOOST_TEST_SUITE( "test_suite1" );
  ts1->add( BOOST_TEST_CASE( &test_case1 ) );
  framework::master_test_suite().add( ts1 );
  return 0;
}

But I get the following error:

..\src\test.cpp: In function 'boost::unit_test::test_suite* init_unit_test_suite(int, char**)': ..\src\test.cpp:23:1: error: redefinition of 'boost::unit_test::test_suite*
init_unit_test_suite(int, char**)' C:\Boost/boost/test/unit_test_suite.hpp:223:1: error: 'boost::unit_test::test_suite* init_unit_test_suite(int, char**)' previously defined here

How to fix this?

Andry
  • 16,172
  • 27
  • 138
  • 246
Anton Frolov
  • 291
  • 4
  • 15
  • Interesting enough, I've just compiled your example with gcc 4.6.2 and it gave no errors at all. I remember having similar error messages though. That time I was using #define BOOST_TEST_MAIN macro and getting rid of it was enough to get it work, but it doesn't seem to be your case. – dianull Mar 21 '12 at 13:50

1 Answers1

2

You must have defined BOOST_TEST_MAIN on the compiler's command line (or in your project settings if you are using VS).

Defining BOOST_TEST_MAIN introduces the method, which you re-introduce later:

// ************************************************************************** //
// **************                BOOST_TEST_MAIN               ************** //
// ************************************************************************** //

#if defined(BOOST_TEST_MAIN)

#ifdef BOOST_TEST_ALTERNATIVE_INIT_API
bool init_unit_test()                   {
#else
::boost::unit_test::test_suite*
init_unit_test_suite( int, char* [] )   {
#endif

http://svn.boost.org/svn/boost/trunk/boost/test/unit_test_suite.hpp

mockinterface
  • 14,452
  • 5
  • 28
  • 49