Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top