Issues Installing and using Boost unit testing framework

488 views Asked by At

I installed boost on my mac like so brew install boost and then created a file called BoostTest.cpp containing the following minimal example:

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

int add(int i, int j)
{
  return i + j;
}

BOOST_AUTO_TEST_CASE(universeInOrder)
{
  BOOST_CHECK(add(2, 2) == 4);
}

I then attempted to compile it like so:

g++ -lboost_unit_test_framework BoostTest.cpp -o BoostTest

And got the resulting output:

Undefined symbols for architecture x86_64:
  "boost::unit_test::ut_detail::normalize_test_case_name[abi:cxx11](boost::unit_test::basic_cstring<char const>)", referenced from:
  boost::unit_test::make_test_case(boost::function<void ()> const&, boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>, unsigned long) in cc2uldAx.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

What did I do wrong and how can I get this working?

1

There are 1 answers

0
Mustafa Sabur On

Looks like you need to set it to c++11.

Try this:

clang++ -std=c++11 -lboost_unit_test_framework -L/usr/local/lib -I/usr/local/include BoostTest.cpp -o BoostTest