1

I am trying to practice using Boost unit testing but am faced with a LNK2019 error. This error code haunts me as I rarely know what needs to be done to fix it.

I have the unit testing class set up as basic as I possibly could. I am just trying to make the basic functions work right now so I can go in and create real tests. This is what I have in my cpp:

#include <boost/test/unit_test.hpp>
#define BOOST_TEST_MODULE unit_test

BOOST_AUTO_TEST_CASE(MyTest)
{
    BOOST_CHECK(10 == 10);
    BOOST_REQUIRE(10 == 11);
}

I have the boost directory included in my C++ project properties, and I have included the stage\lib directory in my Linker Additional Library Directories. I am guessing I have the boost directory included incorrectly, but I am really not sure what I did wrong or how to remedy this. The error is listed below.

Severity    Code    Line    Suppression State   Description
Error   LNK2019 C:\Users\...\libboost_unit_test_framework-vc142-mt-gd-x32-1_71.lib(unit_test_main.obj)  1       unresolved external symbol "class boost::unit_test::test_suite * __cdecl init_unit_test_suite(int,char * * const)" (?init_unit_test_suite@@YAPAVtest_suite@unit_test@boost@@HQAPAD@Z) referenced in function __catch$?unit_test_main@unit_test@boost@@YAHP6APAVtest_suite@12@HQAPAD@ZH0@Z$4

Any thoughts?

bmb
  • 361
  • 2
  • 13
  • 1
    You're supposed to define `BOOST_TEST_MODULE` *before* including the UTF header file. Did you build Boost? If yes, did you build static libraries? If you built shared libraries, you also need to define `BOOST_TEST_DYN_LINK`. This is all explained in the [documentation](https://www.boost.org/doc/libs/release/libs/test/doc/html/boost_test/usage_variants.html). – Praetorian Nov 13 '19 at 01:22
  • @Praetorian defining `BOOST_TEST_MODULE` first thing fixed my issue. Thanks. Should have read the documentation more carefully! – bmb Nov 13 '19 at 01:26
  • Possible duplicate of [Problem with Boost::Test](https://stackoverflow.com/questions/4132635/problem-with-boosttest) – JaMiT Nov 13 '19 at 02:21
  • @Praetorian, yes, it solves my problem. Why don't you make it an anwser? – Zhang May 05 '22 at 12:06

0 Answers0