9

I am trying to use Boost Test to add some much needed unit tests to my code. However I can't seem to get it to work. Right now I have the following code

#include <Drawing.h>
#define BOOST_AUTO_TEST_MAIN
#define BOOST_TEST_MODULE DrawingModelTests
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(DrawingModelTests)

BOOST_AUTO_TEST_CASE ( DrawingConstructorTest)
{
    Drawing * drawing = new Drawing;

    delete drawing;
}

BOOST_AUTO_TEST_SUITE_END()

From what I understand I don't need to put a main or anything since boost will take care of it himself. However Visual Studio keep giving me a "entry point must be defined" error. Do I need to manually add a link to the static library or something? I am compiling as a standard .exe console application.

Laurent Bourgault-Roy
  • 2,774
  • 1
  • 30
  • 36

5 Answers5

19

Add /SUBSYSTEM:CONSOLE to the linker flags. In the project settings, this is on the Linker->System page. You can use boost as either dynamic or static library.

Khouri Giordano
  • 191
  • 1
  • 3
  • 1
    I had the same problem, using the Google Test library, and linking to gtest_main.lib. This fixed that as well. – user75810 Feb 23 '11 at 17:22
10

I had this problem with VS2010 and the solution was to set 'Configuration Properties -> Linker -> Advanced -> Entry Point' to 'main' for the project.

Shane
  • 1,207
  • 13
  • 16
1

I set 'Configuration Properties -> Linker -> Advanced -> Entry Point' to 'mainCRTStartup', which does the trick for me. (In my particular build configuration I'm statically linking boost libraries).

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
1

My code is similar, and works fine. The only difference I can see is that I don't define BOOST_AUTO_TEST_MAIN at all. BOOST_TEST_MODULE tells it where to define main, as far as I'm aware.

jalf
  • 243,077
  • 51
  • 345
  • 550
0

In the end, the way to make it work was to use boost.test as a dynamic library instead of a static library.

Laurent Bourgault-Roy
  • 2,774
  • 1
  • 30
  • 36