I want to serialize objects in my program using the Boost library. It is my first time using it and it is giving me some problems.
In my program I have implemented the "serialize" method and include the following:
#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
Now when I build I get the following errors:
Undefined symbols for architecture x86_64:
"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 Main.o
"boost::archive::detail::basic_oarchive::~basic_oarchive()", referenced from:
boost::archive::detail::common_oarchive<boost::archive::text_oarchive>::~common_oarchive()in Main.o
boost::archive::detail::common_oarchive<boost::archive::text_oarchive>::~common_oarchive()in Main.o
boost::archive::detail::common_oarchive<boost::archive::text_oarchive>::~common_oarchive()in Main.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 Main.o
boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::~text_oarchive_impl()in Main.o
boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::~text_oarchive_impl()in Main.o
"vtable for boost::archive::archive_exception", referenced from:
boost::archive::archive_exception::archive_exception(boost::archive::archive_exception const&)in Main.o
"typeinfo for boost::archive::archive_exception", referenced from:
void boost::serialization::throw_exception<boost::archive::archive_exception>(boost::archive::archive_exception const&)in Main.o
"boost::archive::archive_exception::~archive_exception()", referenced from:
void boost::serialization::throw_exception<boost::archive::archive_exception>(boost::archive::archive_exception const&)in Main.o
void boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::save<boost::archive::tracking_type>(boost::archive::tracking_type const&)in Main.o
void boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::save<boost::archive::object_reference_type>(boost::archive::object_reference_type const&)in Main.o
void boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::save<boost::archive::object_id_type>(boost::archive::object_id_type const&)in Main.o
void boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::save<unsigned int>(unsigned int const&)in Main.o
void boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::save<boost::archive::class_id_reference_type>(boost::archive::class_id_reference_type const&)in Main.o
void boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::save<boost::archive::class_id_type>(boost::archive::class_id_type const&)in Main.o
...
"boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::exception_code, char const*, char const*)", referenced from:
void boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::save<boost::archive::tracking_type>(boost::archive::tracking_type const&)in Main.o
void boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::save<boost::archive::object_reference_type>(boost::archive::object_reference_type const&)in Main.o
void boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::save<boost::archive::object_id_type>(boost::archive::object_id_type const&)in Main.o
void boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::save<unsigned int>(unsigned int const&)in Main.o
void boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::save<boost::archive::class_id_reference_type>(boost::archive::class_id_reference_type const&)in Main.o
void boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::save<boost::archive::class_id_type>(boost::archive::class_id_type const&)in Main.o
"boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::newtoken()", referenced from:
void boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save<boost::archive::tracking_type>(boost::archive::tracking_type const&)in Main.o
void boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save<boost::archive::object_reference_type>(boost::archive::object_reference_type const&)in Main.o
void boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save<boost::archive::object_id_type>(boost::archive::object_id_type const&)in Main.o
void boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save<unsigned int>(unsigned int const&)in Main.o
void boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save<boost::archive::class_id_reference_type>(boost::archive::class_id_reference_type const&)in Main.o
void boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save<boost::archive::class_id_type>(boost::archive::class_id_type const&)in Main.o
"boost::archive::detail::basic_oarchive::end_preamble()", referenced from:
void boost::archive::save_access::save_primitive<boost::archive::text_oarchive, boost::archive::tracking_type>(boost::archive::text_oarchive&, boost::archive::tracking_type const&)in Main.o
void boost::archive::save_access::save_primitive<boost::archive::text_oarchive, boost::archive::object_reference_type>(boost::archive::text_oarchive&, boost::archive::object_reference_type const&)in Main.o
void boost::archive::save_access::save_primitive<boost::archive::text_oarchive, boost::archive::object_id_type>(boost::archive::text_oarchive&, boost::archive::object_id_type const&)in Main.o
void boost::archive::save_access::save_primitive<boost::archive::text_oarchive, boost::archive::version_type>(boost::archive::text_oarchive&, boost::archive::version_type const&)in Main.o
void boost::archive::save_access::save_primitive<boost::archive::text_oarchive, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >(boost::archive::text_oarchive&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in Main.o
void boost::archive::save_access::save_primitive<boost::archive::text_oarchive, boost::archive::class_id_reference_type>(boost::archive::text_oarchive&, boost::archive::class_id_reference_type const&)in Main.o
void boost::archive::save_access::save_primitive<boost::archive::text_oarchive, boost::archive::class_id_type>(boost::archive::text_oarchive&, boost::archive::class_id_type const&)in Main.o
...
"boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save(std::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::basic_string<char, std::char_traits<char>, std::allocator<char> > >(boost::archive::text_oarchive&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in Main.o
"typeinfo for boost::archive::detail::basic_oarchive", referenced from:
typeinfo for boost::archive::detail::common_oarchive<boost::archive::text_oarchive>in Main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [stable] Error 1
I am not sure if the problem is because of linking or if it has something to do with 64 bit and 32 bit architecture.
I have tried linking with:
-L/opt/local/lib/ -lboost_iostreams -lboost_serialization
But it does not seem to do any difference.
It looks like your boost library bundle is 32 bit only; you'll have to rebuild it adding 64 bit binaries, or set your main project to match the boost libraries. Try setting your project to generate a 32 bit binary instead of 64 bit. In XCode 4.2, you'd use the Architecture section of the build settings in the project inspector.
In my case: It is because I used compiler gcc6 (or gcc5 has same issue). And my code used different compile flag with boost libraries. Detail explanation is in this link
If you can recompile all incompatible libs you use, do it with compiler option
-D_GLIBCXX_USE_CXX11_ABI=1
and then rebuild your project. If still can not link, add change project's makefile compiler option to 0.
-D_GLIBCXX_USE_CXX11_ABI=0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With