Cannot Build Simple Boost XML Serialization Example
I'm trying to work with the Boost Serialization libraries for some experimenting on upcoming projects
I know that the Boost Serialization library must be compiled separately from the rest of the projects/headers. I've installed a package for this on Ubuntu 10.04 including boost1.40-dev and the Serialization library, libboost-serialization1.40.0.
In my new Net Beans project, I tried a simple example to see if I could get things running. Here's the example:
/*
* File: main.C
* Author: Doug Swain
*
* Created on January 20, 2011, 11:05 AM
*/
#include <fstream>
#include <iostream>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
int main() {
std::ofstream ofs("filename.xml");
boost::archive::xml_oarchive oa(ofs);
return 0;
}
And then here are the compiler errors:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/doug/BoostSerialization'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/boostserialization
make[2]: Entering directory `/home/doug/BoostSerialization'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
g++ -c -g -I/usr/include/boost/serialization -I/usr/include/boost -I/usr/include/boost/archive -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.C
mkdir -p dist/Debug/GNU-Linux-x86
g++ -o dist/Debug/GNU-Linux-x86/boostserialization build/Debug/GNU-Linux-x86/main.o -L/usr/include/boost/serialization -L/usr/include/boost -L/usr/include/boost/archive
build/Debug/GNU-Linux-x86/main.o: In function `xml_oarchive':
/usr/include/boost/archive/xml_oarchive.hpp:100: undefined reference to `boost::archive::xml_oarchive_impl<boost::archive::xml_oarchive>::xml_oarchive_impl(std::basic_ostream<char, std::char_traits<char> >&, unsigned int)'
build/Debug/GNU-Linux-x86/main.o: In function `~xml_oarchive_impl':
/usr/include/boost/archive/xml_oarchive.hpp:73: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::~basic_xml_oarchive()'
/usr/include/boost/archive/xml_oarchive.hpp:73: undefined reference to `boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::~basic_text_oprimitive()'
/usr/include/boost/archive/xml_oarchive.hpp:73: undefined reference to `boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::~basic_text_oprimitive()'
/usr/include/boost/archive/xml_oarchive.hpp:73: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::~basic_xml_oarchive()'
/usr/include/boost/archive/xml_oarchive.hpp:73: undefined reference to `boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::~basic_text_oprimitive()'
/usr/include/boost/archive/xml_oarchive.hpp:73: undefined reference to `boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::~basic_text_oprimitive()'
/usr/include/boost/archive/xml_oarchive.hpp:73: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::~basic_xml_oarchive()'
/usr/include/boost/archive/xml_oarchive.hpp:73: undefined reference to `boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::~basic_text_oprimitive()'
/usr/include/boost/archive/xml_oarchive.hpp:73: undefined reference to `boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::~basic_text_oprimitive()'
build/Debug/GNU-Linux-x86/main.o:(.rodata._ZTIN5boost7archive6detail15common_oarchiveINS0_12xml_oarchiveEEE[typeinfo for boost::archive::detail::common_oarchive<boost::archive::xml_oarchive>]+0x10): undefined reference to `typeinfo for boost::archive::detail::basic_oarchive'
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::xml_oarchive& boost::archive::detail::interface_oarchive<boost::archive::xml_oarchive>::operator<< <boost::archive::version_type const>(boost::archive::version_type const&)':
/usr/include/boost/archive/detail/interface_oarchive.hpp:64: undefined reference to `boost::arc开发者_开发知识库hive::basic_xml_oarchive<boost::archive::xml_oarchive>::save_override(boost::archive::version_type const&, int)'
make[2]: Leaving directory `/home/doug/BoostSerialization'
make[1]: Leaving directory `/home/doug/BoostSerialization'
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::xml_oarchive& boost::archive::detail::interface_oarchive<boost::archive::xml_oarchive>::operator<< <boost::archive::object_id_type const>(boost::archive::object_id_type const&)':
/usr/include/boost/archive/detail/interface_oarchive.hpp:64: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::save_override(boost::archive::object_id_type const&, int)'
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::xml_oarchive& boost::archive::detail::interface_oarchive<boost::archive::xml_oarchive>::operator<< <boost::archive::object_reference_type const>(boost::archive::object_reference_type const&)':
/usr/include/boost/archive/detail/interface_oarchive.hpp:64: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::save_override(boost::archive::object_reference_type const&, int)'
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::xml_oarchive& boost::archive::detail::interface_oarchive<boost::archive::xml_oarchive>::operator<< <boost::archive::class_id_type const>(boost::archive::class_id_type const&)':
/usr/include/boost/archive/detail/interface_oarchive.hpp:64: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::save_override(boost::archive::class_id_type const&, int)'
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::xml_oarchive& boost::archive::detail::interface_oarchive<boost::archive::xml_oarchive>::operator<< <boost::archive::class_id_optional_type const>(boost::archive::class_id_optional_type const&)':
/usr/include/boost/archive/detail/interface_oarchive.hpp:64: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::save_override(boost::archive::class_id_optional_type const&, int)'
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::xml_oarchive& boost::archive::detail::interface_oarchive<boost::archive::xml_oarchive>::operator<< <boost::archive::class_id_reference_type const>(boost::archive::class_id_reference_type const&)':
/usr/include/boost/archive/detail/interface_oarchive.hpp:64: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::save_override(boost::archive::class_id_reference_type const&, int)'
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::xml_oarchive& boost::archive::detail::interface_oarchive<boost::archive::xml_oarchive>::operator<< <boost::archive::class_name_type const>(boost::archive::class_name_type const&)':
/usr/include/boost/archive/detail/interface_oarchive.hpp:64: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::save_override(boost::archive::class_name_type const&, int)'
build/Debug/GNU-Linux-x86/main.o: In function `boost::archive::xml_oarchive& boost::archive::detail::interface_oarchive<boost::archive::xml_oarchive>::operator<< <boost::archive::tracking_type const>(boost::archive::tracking_type const&)':
/usr/include/boost/archive/detail/interface_oarchive.hpp:64: undefined reference to `boost::archive::basic_xml_oarchive<boost::archive::xml_oarchive>::save_override(boost::archive::tracking_type const&, int)'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/boostserialization] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
I've verified that the headers do in fact exist (and NetBeans can find it prior to trying to build them). I've also made sure to update the include directories and the library directories to the best of my knowledge:
These are not compiler errors, but linker errors. You need to link in the Boost serialization library, probably called libboost_serialization.a
or something along those lines.
More than including headers file from boost, you have to link to boost libraries to be able to use its functions.
精彩评论