1

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.

user2751691
  • 401
  • 2
  • 10
  • 32
  • Try including `-I/usr/local/boost_1_57_0` in your compiler flags. – bdesham Mar 17 '15 at 21:57
  • @bdesham : Hi, I have added the Makefile. I tried to add the -I/usr/local/boost_1_57_0 between $(CXX) and -o$@ $^, but it gave a linker problem. It could not find lboost_unit_test_framework in the makefile. Is that the right place to put it? Could you help please? – user2751691 Mar 17 '15 at 22:04
  • Please update the Makefile showing us where you put the `-I` flag, and please also include the full text of the linker error you are getting. – bdesham Mar 17 '15 at 22:20
  • @bdesham : Hi, I updated the changes I made at the bottom. Please help to take a look. Thank you. – user2751691 Mar 17 '15 at 22:27
  • 1
    You need to pass an `-L` option to the compiler too, to tell it where the Boost libraries are. I’m not sure where they are on your system but hopefully this is enough information for you to go on. – bdesham Mar 17 '15 at 23:33
  • @bdesham : Hi, are you talking about the include path? 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. – user2751691 Mar 18 '15 at 20:52
  • Sorry, I’m not sure what else to suggest. Maybe ask on a Boost-specific forum or mailing list? – bdesham Mar 18 '15 at 22:25

0 Answers0