I need to incorporate Boost.Test into my C++ program on macOS. Before doing so I first need to test makefiles using an example: https://github.com/jsankey/boost.test-examples The makefile included does not work so I modified it.
TARGETS=main hello suites fixtures assertions
INC=-I/usr/local/boost/include
LDFLAGS=-L/usr/local/lib -lboost_unit_test_framework
all: $(TARGETS)
test: $(TARGETS) $(addprefix run-,$(TARGETS))
main.o: main.cpp
$(CXX) $< $(INC) -c
hello.o: hello.cpp
$(CXX) $< $(INC) -c
suites.o: suites.cpp
$(CXX) $< $(INC) -c
fixtures.o: fixtures.cpp
$(CXX) $< $(INC) -c
assertions.o: assertions.cpp
$(CXX) $< $(INC) -c
main: main.o
$(CXX) $^ $(LDFLAGS) -o $@
hello: hello.o
$(CXX) $^ $(LDFLAGS) -o $@
suites: suites.o
$(CXX) $^ $(LDFLAGS) -o $@
fixtures: fixtures.o
$(CXX) $^ $(LDFLAGS) -o $@
assertions: assertions.o
$(CXX) $^ $(LDFLAGS) -o $@
run-%: %
-./$^ --output_format=XML --log_level=test_suite > $(^)-report.xml
clean:
rm $(TARGETS) *-report.xml
EDITED: Now compiling works well. Linking on the other hand causes an error, namely the following:
ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd Undefined symbols for architecture x86_64: "__Unwind_Resume", referenced from: boost::unit_test::singleton::instance() in hello.o boost::unit_test::make_test_case(boost::function const&, boost::unit_test::basic_cstring, boost::unit_test::basic_cstring, unsigned long) in hello.o universeInOrder_invoker() in hello.o boost::unit_test::singleton::instance() in hello.o universeInOrder::test_method() in hello.o boost::unit_test::lazy_ostream::instance() in hello.o boost::basic_wrap_stringstream::str() in hello.o ... "___bzero", referenced from: universeInOrder_invoker() in hello.o "___cxa_atexit", referenced from:
boost::unit_test::singleton::instance() in hello.o boost::unit_test::singleton::instance() in hello.o boost::unit_test::lazy_ostream::instance() in hello.o "_memcpy", referenced from: std::__1::char_traits::copy(char*, char const*, unsigned long) in hello.o "_memset", referenced from: std::__1::ostreambuf_iterator > std::__1::__pad_and_output >(std::__1::ostreambuf_iterator >, char const*, char const*, char const*, std::__1::ios_base&, char) in hello.o std::__1::char_traits::assign(char*, unsigned long, char) in hello.o boost::basic_wrap_stringstream::basic_wrap_stringstream() in hello.o std::__1::basic_stringbuf, std::__1::allocator >::seekoff(long long, std::__1::ios_base::seekdir, unsigned int) in hello.o std::__1::basic_stringbuf, std::__1::allocator >::str() const in hello.o std::__1::basic_ostream >& boost::unit_test::operator<<, char const>(std::__1::basic_ostream >&, boost::unit_test::basic_cstring const&) in hello.o "_strcmp", referenced from:
boost::typeindex::stl_type_index::equal(boost::typeindex::stl_type_index const&) const in hello.o "_strlen", referenced from: std::__1::char_traits::length(char const*) in hello.o ld: symbol(s) not found for architecture x86_64 clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [Makefile:21: hello] Error 1