2010-12-06 20 views
1

私はboost.testをブースト1.33.1のリモートシステムで使用しようとしています。私のPC上でhttp://www.boost.org/doc/libs/1_42_0/libs/test/doc/html/tutorials/hello-the-testing-world.html作品から、この小さな例:古いバージョンのboost.testでの問題

#define BOOST_TEST_MODULE MyTest 
#include <boost/test/included/unit_test.hpp> // I've changed here 

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

BOOST_AUTO_TEST_CASE(my_test) // <--- line 7 
{ 
// 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 
} 

が、ファイルunit_test.hppが存在しないリモートシステム上。私のPC上のファイルunit_test_framework.hppは、単純に:

// deprecated 
#include <boost/test/included/unit_test.hpp> 

であり、メインシステムに存在します。だから私はに含める変更しようとしました:

#include <boost/test/included/unit_test_framework.hpp> 

コンパイラは言う:

main.cpp:7: error: expected constructor, destructor, or type conversion before ‘(’ token 

これを何ですか?どのようにそれを解決するには?

+0

どのシステムで含める? –

+0

リモートシステムにどのバージョンのブーストがインストールされているか教えてください。 – jopasserat

+0

remote:1.33.1、local:1.36.0 –

答えて

3

#define BOOST_AUTO_TEST_MAIN 

か、リンカエラーを取得します

0

バージョンが1.33より古い場合は、BOOST_AUTO_TEST_CASEBOOST_AUTO_UNIT_TESTに変更してください。新しいバージョンのブーストではブレークしないでください。

は、これらのBoost.Test 1.33 Release Notesを参照してください。 BOOST_AUTO_TEST_CASEに改名

BOOST_AUTO_UNIT_TEST。旧名称はまだ が提供されていますが、廃止予定です

+0

私はまったく同じメッセージを出しました。 'BOOST_AUTO_TEST_CASE'は' boost/test/auto_unit_test.hpp'で定義されていると思います。しかし、私がそれをインクルードすると、 'init_unit_test_suite(int、char **) 'への未定義の参照が返されます。 –

+0

@wiso:' undefined reference'は実際には非常に異なるエラーです! boost.testライブラリにリンクする必要があります – icecrime

+1

私はすでに '-lboost_unit_test_framework'を使用していますが、リンクする必要がありますか? –

0

ターゲットプラットフォームのブーストバージョンとは何ですか?あなたはそこに古いバージョンを使用していますか?

boost.testのヘッダーのみのバージョン(boost/test/included/unit_test.hppヘッダーを含み、boost/test/unit_test.hppは含まない)を使用しているので、作業ブーストをコピーできませんお使いのPCからターゲットマシンにインストールして、コンパイラに使用するよう指示しますか?

の代わりに
#include <boost/test/auto_unit_test.hpp> 

#include <boost/test/unit_test.hpp> 

もの#include追加する前に:ブースト1.33使用上の

関連する問題