简体   繁体   中英

init_unit_test_suite redefinition error

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM