I am using boost serialization. I compiled with: -L/opt/local/lib -lboost_serialization -stdlib=libc++
, but got several (ungooglable) errors:
Undefined symbols for architecture x86_64: "boost::archive::text_oarchive_impl::save(std::__1::basic_string, std::__1::allocator > const&)", referenced from: void boost::archive::save_access::save_primitive, std::__1::allocator > >(boost::archive::text_oarchive&, std::__1::basic_string, std::__1::allocator > const&) in main.o "boost::archive::basic_text_oprimitive > >::~basic_text_oprimitive()", referenced from: boost::archive::text_oarchive_impl::~text_oarchive_impl() in main.o "boost::archive::text_oarchive_impl::text_oarchive_impl(std::__1::basic_ostream >&, unsigned int)", referenced from: boost::archive::text_oarchive::text_oarchive(std::__1::basic_ostream >&, unsigned int) in main.o ld: symbol(s) not found for architecture x86_64
I am serializing an std::vector<std::string>
:
boost::archive::text_oarchive oa(std::cout);
oa << tasks;
Is there a problem with my installation of boost?
The boost libraries are universal binaries containing both 32-bit and 64-bit machine code (so that's not the problem I guess):
$ file libboost_serialization.dylib libboost_serialization.dylib: Mach-O universal binary with 2 architectures libboost_serialization.dylib (for architecture i386): Mach-O dynamically linked shared library i386 libboost_serialization.dylib (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
I installed boost using sudo port install boost +universal
on Mac OS X 10.7.
Best Answer
I could reproduce the problem using the following code:
This compiles and links without problems when using
g++
orclang++
with their respective default flags and linking with-lboost_serialization
. However, when usingclang++
withlibc++
linking fails with essentially the error messages quote (I have Boost installed at/opt/boost
):Based on this I assumed that a build with -stdlib=libc++ wants to have its own Boost build and build one using based on the Boost installation guide:
The edits I made to
clang-darwin.jam
are almost certainly not those intended but they seem to do the trick: I don't know much about "bjam" and I just tried to find an appropriate location to apply the change. Some step of the installation usesudo
to install things into protected directories. Obviously, you can install into some other directory where you have write permissions as well. I just installed things on my machine in a way preventing me from accidentally messing it up.However, with this installation in place I could successfully build the program: