2

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

Ying Zhou
  • 189
  • 3
  • 16
  • 1
    You claim boost is installed here, `/usr/local/boost/include` I do not see `include` as a subdirectory in your `INC` setting. – PaulMcKenzie Feb 23 '19 at 21:02
  • @PaulMcKenzie I have changed that. The problem persists. – Ying Zhou Feb 23 '19 at 21:06
  • 1
    I think you need to include -I /usr/local/boost/include in your search path - not /usr/local/boost. – natersoz Feb 23 '19 at 21:18
  • @natersoz This has been changed. The problem persists though. – Ying Zhou Feb 23 '19 at 21:20
  • 1
    The include path is not showing up in your command line. There is no "-I/usr/local/boost/include" found there. I'll take another look. – natersoz Feb 23 '19 at 21:25
  • @natersoz You are right. Now I have a different problem. – Ying Zhou Feb 23 '19 at 21:32
  • 1
    Unresolved symbols to log stuff with mangled names ... ? – natersoz Feb 23 '19 at 21:48
  • @natersoz Well I'm suspecting Anaconda being the cause of the problem now. It messes up cmake as well. – Ying Zhou Feb 23 '19 at 21:49
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/188940/discussion-between-ying-zhou-and-natersoz). – Ying Zhou Feb 23 '19 at 22:04
  • 1
    I also work primarily with a mac (OSX) and get the same errors. See this Q/A session: https://stackoverflow.com/questions/8685045/xcode-with-boost-linkerid-warning-about-visibility-settings Compiling and linking on Linux (I have a VM for this) works fine. There is something stupid going on in LLVM/OSX land. The answer is somewhere in that thread. – natersoz Feb 23 '19 at 22:37

0 Answers0