title: Boost::Test -- generation of Main()?
body: <p>I'm a bit confused on setting up the boost test library. Here is my code:</p>
  
  <pre><code>#include "stdafx.h"
  #define BOOST_TEST_DYN_LINK
  #define BOOST_TEST_MODULE pevUnitTest
  #include &lt;boost/test/unit_test.hpp&gt;
  
  BOOST_AUTO_TEST_CASE( TesterTest )
  {
      BOOST_CHECK(true);
  }
  </code></pre>
  
  <p>My compiler generates the wonderfully useful error message:</p>
  
  <pre><code>1&gt;MSVCRTD.lib(wcrtexe.obj) : error LNK2019: unresolved external symbol _wmain referenced in function ___tmainCRTStartup
  1&gt;C:\Users\Billy\Documents\Visual Studio 10\Projects\pevFind\Debug\pevUnitTest.exe : fatal error LNK1120: 1 unresolved externals
  </code></pre>
  
  <p>It seems that the Boost::Test library is not generating a main() function -- I was under the impression it does this whenever <code>BOOST_TEST_MODULE</code> is defined. But ... the linker error continues.</p>
  
  <p>Any ideas?</p>
  
  <p>Billy3</p>
  
  <p>EDIT: Here's my code to work around the bug described in the correct answer below:</p>
  
  <pre><code>#include "stdafx.h"
  #define BOOST_TEST_MODULE pevUnitTests
  #ifndef _UNICODE
  #define BOOST_TEST_MAIN
  #endif
  #define BOOST_TEST_DYN_LINK
  #include &lt;boost/test/unit_test.hpp&gt;
  
  #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 &lt; 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( &amp;init_unit_test, argc, utf8Lines );
      //End from boost::test's main()
  
      //Clean up our mess
      for(unsigned int idx = 0; idx &lt; argc + 1; idx++)
          delete [] utf8Lines[idx];
      delete [] utf8Lines;
  
      return returnValue;
  }
  
  #endif
  
  BOOST_AUTO_TEST_CASE( TesterTest )
  {
      BOOST_CHECK(false);
  }
  </code></pre>
  
  <p>Hope that's helpful to someone.</p>
  
  <p>Billy3</p>