My bad!! Ever wonder what causes this error in my Boost Test?
crt0_c.c:-1: error: undefined reference to `WinMain@16'
collect2.exe:-1: error: error: ld returned 1 exit status
I was in the midst of preparing a new test script for my unit test, but somehow I was so struggling when I got hit on that error. Googling around couldn't find any answer, I sit back and doing code review again on my unit test script. What is surprising me is that I was missing the one time setup code in the beginning of the code:
#define BOOST_TEST_DYN_LINK
#define BOOST_NO_CXX11_SCOPED_ENUMS
#define BOOST_TEST_MODULE "syncFile core function"
#include <initializer_list>
#include <boost/test/unit_test.hpp>
...
The first line is very important, this is the crucial part of the success or failure of the compilation. What if I have multiple unit test source file, and
BOOST_TEST_DYN_LINK was declared in both files? I am using QT compiler, script below shows 2 unit test source files was included in the project:
...
SOURCES += \
../unittest/testCaptureFiles.cpp \
../unittest/testlab.cpp
...
This is what I got from the compiler:
D:\tool\boost_1_61_0\boost\test\unit_test_suite.hpp:338: error: multiple definition of `init_unit_test()'
D:\tool\boost_1_61_0\boost\test\unit_test.hpp:62: error: multiple definition of `main'
collect2.exe:-1: error: error: ld returned 1 exit status
So please be careful on using Boost Test.
No comments:
Post a Comment