简体   繁体   中英

c++ BOOST_TEST not in scope

I'm using boost version 1.58

Boost appears to be installed correctly, and the following code compiles and runs correctly (giving an error on the third check):

#define BOOST_TEST_MODULE basics_test

#include <boost/test/included/unit_test.hpp>

BOOST_AUTO_TEST_CASE( basics_test ) {
  BOOST_CHECK(1 == 1);
  BOOST_CHECK(1 + 2 < 4);
  BOOST_CHECK(1 == 2);
}

However, when I attempt to run the second example from the site http://www.boost.org/doc/libs/1_59_0/libs/test/doc/html/boost_test/testing_tools/boost_test_universal_macro.html , I get the error:

test.cpp: In member function ‘void test_op_reportings::test_method()’:
test.cpp:20:20: error: ‘BOOST_TEST’ was not declared in this scope
   BOOST_TEST(a == b);

When I change each instance of BOOST_TEST to BOOST_CHECK, the code compiles and runs normally. I'm using g++; when I configure g++ to use c++11 as in g++ -std=c++11 test cpp -o main I get the same error.

How should I go about fixing this?

The documents you are looking at are for Boost 1.59, yet you are using boost 1.58. what makes you think BOOST_TEST existed in 1.58?

From the 1.58 documentation, I only see support for BOOST_TEST_MESSAGE and other alternatives.

Either upgrade your Boost to at least 1.59 where the documentation shows you have BOOST_TEST , or use the features available in 1.58 such as what you have already done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM