问题安装和使用Boost单元测试框架

时间:2016-12-31 15:14:08

标签: c++ unit-testing boost boost-test

我在我的mac上安装了boost brew install boost,然后创建了一个名为BoostTest.cpp的文件,其中包含以下最小示例:

#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);
}

然后我试图像这样编译它:

g++ -lboost_unit_test_framework BoostTest.cpp -o BoostTest

得到了结果输出:

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

我做错了什么,我怎么能让它发挥作用?

1 个答案:

答案 0 :(得分:1)

看起来你需要将它设置为c ++ 11。

试试这个:

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