I'm following JetBrains's tutorial on an Apple Silicon computer. I installed boost with MacPorts (sudo port install boost), the version is 1.71 The build of tests.cpp file fails with the following error:
ld: warning: ignoring file /opt/local/lib/libboost_unit_test_framework-mt.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
"boost::test_tools::tt_detail::report_assertion(boost::test_tools::assertion_result const&, boost::unit_test::lazy_ostream const&, boost::unit_test::basic_cstring<char const>, unsigned long, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, unsigned long, ...)", referenced from:
my_testsuite::addvalues_zero::test_method() in tests.cpp.o
my_testsuite::addvalues_negpos::test_method() in tests.cpp.o
"boost::test_tools::tt_detail::format_assertion_result(boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>)", referenced from:
boost::test_tools::assertion::binary_expr<boost::test_tools::assertion::value_expr<int>, int, boost::test_tools::assertion::op::EQ<int, int, void> >::evaluate(bool) const in tests.cpp.o
"boost::unit_test::lazy_ostream::inst", referenced from:
boost::unit_test::lazy_ostream::instance() in tests.cpp.o
"boost::unit_test::unit_test_main(bool (*)(), int, char**)", referenced from:
_main in tests.cpp.o
"boost::unit_test::unit_test_log_t::set_checkpoint(boost::unit_test::basic_cstring<char const>, unsigned long, boost::unit_test::basic_cstring<char const>)", referenced from:
my_testsuite::addvalues_zero_invoker() in tests.cpp.o
my_testsuite::addvalues_zero::test_method() in tests.cpp.o
my_testsuite::addvalues_negpos_invoker() in tests.cpp.o
my_testsuite::addvalues_negpos::test_method() in tests.cpp.o
"boost::unit_test::unit_test_log_t::instance()", referenced from:
___cxx_global_var_init in tests.cpp.o
"boost::unit_test::decorator::collector_t::instance()", referenced from:
___cxx_global_var_init.3 in tests.cpp.o
___cxx_global_var_init.6 in tests.cpp.o
___cxx_global_var_init.10 in tests.cpp.o
"boost::unit_test::framework::impl::master_test_suite_name_setter::master_test_suite_name_setter(boost::unit_test::basic_cstring<char const>)", referenced from:
___cxx_global_var_init.1 in tests.cpp.o
"boost::unit_test::test_case::test_case(boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>, unsigned long, boost::function<void ()> const&)", referenced from:
boost::unit_test::make_test_case(boost::function<void ()> const&, boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>, unsigned long) in tests.cpp.o
"boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>, unsigned long, boost::unit_test::decorator::collector_t&)", referenced from:
___cxx_global_var_init.3 in tests.cpp.o
"boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(boost::unit_test::test_case*, boost::unit_test::decorator::collector_t&, unsigned long)", referenced from:
___cxx_global_var_init.6 in tests.cpp.o
___cxx_global_var_init.10 in tests.cpp.o
"boost::unit_test::ut_detail::auto_test_unit_registrar::auto_test_unit_registrar(int)", referenced from:
___cxx_global_var_init.15 in tests.cpp.o
"boost::unit_test::ut_detail::normalize_test_case_name(boost::unit_test::basic_cstring<char const>)", referenced from:
boost::unit_test::make_test_case(boost::function<void ()> const&, boost::unit_test::basic_cstring<char const>, boost::unit_test::basic_cstring<char const>, unsigned long) in tests.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [test/test] Error 1
make[2]: *** [test/CMakeFiles/test.dir/all] Error 2
make[1]: *** [test/CMakeFiles/test.dir/rule] Error 2
make: *** [test] Error 2
My code in tests.cpp:
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE my_unit_tests
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "../calc.h"
BOOST_AUTO_TEST_SUITE(my_testsuite)
BOOST_AUTO_TEST_CASE(addvalues_zero)
{
BOOST_TEST(add(0, 0) == 0);
BOOST_TEST(add(-5, 5) == 0);
}
BOOST_AUTO_TEST_CASE(addvalues_negpos)
{
BOOST_TEST(add(-5, 10) == 5);
BOOST_TEST(add(-10, 5) == -5);
BOOST_TEST(add(5, 10) == 15);
}
BOOST_AUTO_TEST_SUITE_END()
My code in test/CMakeLists.txt:
set(Boost_USE_STATIC_LIBS OFF)
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
include_directories(${Boost_INCLUDE_DIR})
add_executable(test tests.cpp)
target_link_libraries(test ${Boost_LIBRARIES})
target_link_libraries(test test_lib)
I have the library in the cmake-build-debug folder and I have included the test subproject in the main CMakeLists.txt.