4

ブーストテストライブラリの設定について少し混乱しています。これが私のコードです:

#include "stdafx.h"
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE pevUnitTest
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE( TesterTest )
{
    BOOST_CHECK(true);
}

私のコンパイラは、非常に便利なエラーメッセージを生成します。

1>MSVCRTD.lib(wcrtexe.obj) : error LNK2019: unresolved external symbol _wmain referenced in function ___tmainCRTStartup
1>C:\Users\Billy\Documents\Visual Studio 10\Projects\pevFind\Debug\pevUnitTest.exe : fatal error LNK1120: 1 unresolved externals

BOOST_TEST_MODULEBoost :: Testライブラリはmain()関数を生成していないようです-定義されているときはいつでもこれを実行するという印象を受けました。しかし...リンカーエラーは続きます。

何か案は?

ビリー3

編集:以下の正解で説明されているバグを回避するための私のコードは次のとおりです。

#include "stdafx.h"
#define BOOST_TEST_MODULE pevUnitTests
#ifndef _UNICODE
#define BOOST_TEST_MAIN
#endif
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

#ifdef _UNICODE

int _tmain(int argc, wchar_t * argv[])
{
    char ** utf8Lines;
    int returnValue;

    //Allocate enough pointers to hold the # of command items (+1 for a null line on the end)
    utf8Lines = new char* [argc + 1];

    //Put the null line on the end (Ansi stuff...)
    utf8Lines[argc] = new char[1];
    utf8Lines[argc][0] = NULL;

    //Convert commands into UTF8 for non wide character supporting boost library
    for(unsigned int idx = 0; idx < argc; idx++)
    {
        int convertedLength;
        convertedLength = WideCharToMultiByte(CP_UTF8, NULL, argv[idx], -1, NULL, NULL, NULL, NULL);
        if (convertedLength == 0)
            return GetLastError();
        utf8Lines[idx] = new char[convertedLength]; // WideCharToMultiByte handles null term issues
        WideCharToMultiByte(CP_UTF8, NULL, argv[idx], -1, utf8Lines[idx], convertedLength, NULL, NULL);
    }

    //From boost::test's main()
    returnValue = ::boost::unit_test::unit_test_main( &init_unit_test, argc, utf8Lines );
    //End from boost::test's main()

    //Clean up our mess
    for(unsigned int idx = 0; idx < argc + 1; idx++)
        delete [] utf8Lines[idx];
    delete [] utf8Lines;

    return returnValue;
}

#endif

BOOST_AUTO_TEST_CASE( TesterTest )
{
    BOOST_CHECK(false);
}

それが誰かに役立つことを願っています。

ビリー3

4

1 に答える 1

4

問題は、VC10 ベータ版を使用していることだと思います。

Unicode が有効になっている場合、エントリ ポイントがwmainではなくである必要があるという、楽しい小さなバグがありmainます。(古いバージョンでは、そのような場合にwmainmainの両方を使用できました)。

もちろん、これは次のベータ版で修正される予定ですが、それまでは問題です。:)

VC9 にダウングレードするか、Unicode を無効にするかmain、プロジェクト プロパティでエントリ ポイントを手動で設定してみてください。

別の方法として、main を呼び出す独自の wmain スタブを定義する場合がありますこれは技術的に未定義の動作であると確信していますが、リリースされていないコンパイラのコンパイラのバグの回避策として、うまくいく可能性があります。

于 2009-08-09T14:38:21.500 に答える