I am new to boost.test library. I have boost downloaded before by MacPorts, and I can locate locally /usr/local/boost_1_57_0/boost/test/unit_test.hpp
Then I find an open source, and downloaded the zip folder. The url is here: https://github.com/jsankey/boost.test-examples
Then I cd to that download directory and tried to run make
as the README said, but it threw an error:
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
Then I tried to just run one hello.cpp file by
g++ -o hello -lboost_unit_test_framework hello.cpp
Then it still threw the error:
hello.cpp:3:10: fatal error: 'boost/test/unit_test.hpp' file not found
#include <boost/test/unit_test.hpp>
^
1 error generated.
The hello.cpp contains a basic test case as follows:
#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);
}
The current Makefile is:
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
Where did I do wrong, or what I should have done to make it compile please? Thank you so much.
Edit:
I used g++ -I/usr/local/boost_1_57_0 -I/opt/local/include -L/opt/local/lib hello.cpp -o hello -lboost_unit_test_framework
then it's complaining
ld: library not found for -lboost_unit_test_framework
clang: error: linker command failed with exit code 1 (use -v to see invocation).
I tried to download the boost_unit_test_framework but did not find a source.