Boost :: Test - generating Main ()?

I am a bit confused about creating a test library. Here is my code:

#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); } 

My compiler generates a surprisingly useful error message:

 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 

It seems that the Boost :: Test library does not generate the main () function - I was under the impression that this is done with every BOOST_TEST_MODULE . But ... the linker error continues.

Any ideas?

Billy3

EDIT: Here, my code is working on the error described in the correct answer below:

 #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 main() returnValue = ::boost::unit_test::unit_test_main( &init_unit_test, argc, utf8Lines ); //End from boost::test 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); } 

Hope this helps someone.

Billy3

+4
source share
1 answer

I think the problem is that you are using a beta version of VC10.

This has a funny little bug where, when Unicode is turned on, it requires the entry point to be wmain , not main . (Older versions allowed you to use both wmain and main in these cases).

Of course, this will be fixed in the next beta, but until then, well, that's the problem. :)

You can either switch to VC9, disable Unicode, or try manually setting the entry point main in the project properties.

Another thing that might work is to define your own wmain stub that main calls. I'm sure this is technically undefined behavior, but as a workaround for a compiler error in an unreleased compiler, this might do the trick.

+4
source

All Articles