I am encountering problems while compiling a c++ program including boost library. The problems seem to have started occuring after I updated to Catalina, before everything worked correctly.
I use boost installed via homebrew ("brew install boost") and compile the program with g++ version 9 als installed with homebrew.
When compiling with "g++-9 -I/usr/local/include -L/usr/local/lib -lboost_serialization test.cc" the libararies are correctly found by the compiler but the following error occurs. Below I include the error message and the test program that causes it.
An interesting observation is that the name in the error message referenced as "cclgNgf3.o" changes each time I compile. So far I also got "ccmG1kWi.o" and "cc25AYXh.o".
Undefined symbols for architecture x86_64:
"boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
void boost::archive::save_access::save_primitive<boost::archive::text_oarchive, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(boost::archive::text_oarchive&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) in cclgNgf3.o
"boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::text_oarchive_impl(std::basic_ostream<char, std::char_traits<char> >&, unsigned int)", referenced from:
boost::archive::text_oarchive::text_oarchive(std::basic_ostream<char, std::char_traits<char> >&, unsigned int) in cclgNgf3.o
"boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::~basic_text_oprimitive()", referenced from:
boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::~text_oarchive_impl() in cclgNgf3.o
boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::~text_oarchive_impl() in cclgNgf3.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
#include <boost/archive/text_oarchive.hpp>
#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
boost::archive::text_oarchive oa{cout};
return 0;
}
On the off chance that it might be relevant when compiling with macOS clang compiler by invoking "g++ -lboost_serialization test.cc" a following error message is printed.
test.cc:8:32: error: no matching constructor for initialization of 'boost::archive::text_oarchive'
boost::archive::text_oarchive oa{cout};
^
/usr/local/include/boost/archive/text_oarchive.hpp:98:28: note: candidate constructor (the implicit copy constructor) not viable: requires 1
argument, but 0 were provided
class BOOST_SYMBOL_VISIBLE text_oarchive :
^
/usr/local/include/boost/archive/text_oarchive.hpp:102:5: note: candidate constructor not viable: requires at least argument 'os_', but no arguments
were provided
text_oarchive(std::ostream & os_, unsigned int flags = 0) :
^
test.cc:8:34: error: expected ';' at end of declaration
boost::archive::text_oarchive oa{cout};
^
;
2 errors generated.