Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with Boost::Test

Why this (copied from boost site ) gives me an error?! in VS 2010 Ultimate:

#include <boost\test\unit_test.hpp>

#define BOOST_TEST_MODULE MyTest


int add( int i, int j ) { return i+j; }

BOOST_AUTO_TEST_CASE( my_test )
{
    // seven ways to detect and report the same error:
    BOOST_CHECK( add( 2,2 ) == 4 );        // #1 continues on error

    BOOST_REQUIRE( add( 2,2 ) == 4 );      // #2 throws on error

    if( add( 2,2 ) != 4 )
      BOOST_ERROR( "Ouch..." );            // #3 continues on error

    if( add( 2,2 ) != 4 )
      BOOST_FAIL( "Ouch..." );             // #4 throws on error

    if( add( 2,2 ) != 4 ) throw "Ouch..."; // #5 throws on error

    BOOST_CHECK_MESSAGE( add( 2,2 ) == 4,  // #6 continues on error
                         "add(..) result: " << add( 2,2 ) );

    BOOST_CHECK_EQUAL( add( 2,2 ), 4 );   // #7 continues on error
}

Error

Error   1   error LNK2019: unresolved external symbol "class boost::unit_test::test_suite * __cdecl init_unit_test_suite(int,char * * const)" (?init_unit_test_suite@@YAPAVtest_suite@unit_test@boost@@HQAPAD@Z) referenced in function _main
like image 652
There is nothing we can do Avatar asked Nov 09 '10 10:11

There is nothing we can do


1 Answers

Try defining BOOST_TEST_MODULE before you include the header.

like image 150
Björn Pollex Avatar answered Sep 23 '22 19:09

Björn Pollex