我是boost.test库的新手。我之前通过MacPorts下载了提升,我可以在本地找到/usr/local/boost_1_57_0/boost/test/unit_test.hpp
然后我找到一个开源,并下载了zip文件夹。网址在这里:https://github.com/jsankey/boost.test-examples
然后我cd到那个下载目录并尝试按照README说的那样运行make
,但是它引发了一个错误:
c++ -omain main.cpp -lboost_unit_test_framework
main.cpp:3:10: fatal error: 'boost/test/unit_test.hpp' file not found
#include <boost/test/unit_test.hpp>
^
1 error generated.
make: *** [main] Error 1
然后我尝试通过
运行一个hello.cpp文件g++ -o hello -lboost_unit_test_framework hello.cpp
然后它仍然抛出错误:
hello.cpp:3:10: fatal error: 'boost/test/unit_test.hpp' file not found
#include <boost/test/unit_test.hpp>
^
1 error generated.
hello.cpp包含一个基本测试用例,如下所示:
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE Hello
#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) == 5);
}
当前的Makefile是:
TARGETS=main hello suites fixtures assertions
all: $(TARGETS)
test: $(TARGETS) $(addprefix run-,$(TARGETS))
%: %.cpp
$(CXX) -o$@ $^ -lboost_unit_test_framework
run-%: %
-./$^ --output_format=XML --log_level=test_suite > $(^)-report.xml
clean:
rm $(TARGETS) *-report.xml
我在哪里做错了,或者我应该做些什么来让它编译好?非常感谢。
编辑:
我使用g++ -I/usr/local/boost_1_57_0 -I/opt/local/include -L/opt/local/lib hello.cpp -o hello -lboost_unit_test_framework
然后抱怨
ld: library not found for -lboost_unit_test_framework
clang: error: linker command failed with exit code 1 (use -v to see invocation).
我尝试下载boost_unit_test_framework但没找到来源。