2010-11-09 66 views
3

爲什麼這個(複製自boost site)給我一個錯誤?在VS 2010旗艦版:升壓問題::測試

#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 1 error LNK2019: unresolved external symbol "class boost::unit_test::test_suite * __cdecl init_unit_test_suite(int,char * * const)" ([email protected]@[email protected][email protected]@@[email protected]) referenced in function _main 

回答

13

嘗試定義BOOST_TEST_MODULE您包括頭前。

+0

現在我得到錯誤:錯誤LNK2019:在功能___tmainCRTStartup – 2010-11-09 10:48:43

+0

@There解析的外部符號_main引用:閱讀[文件](http://boost.org/doc/libs/1_44_0/libs/測試/ DOC/HTML/UTF/compilation.html)。特別是關於自動鏈接的部分。您可能必須手動鏈接庫。目前我無法幫助你。 – 2010-11-09 10:52:50

+0

這是我不時忘記的那些煩人的事情之一。哎呀! Arggggh! – 2010-12-13 14:25:27