Subject: [Boost-bugs] [Boost C++ Libraries] #6107: Boost sample source code cant compile .boost1.33.1 and gcc4.1.2
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-11-09 04:19:45
#6107: Boost sample source code cant compile .boost1.33.1 and gcc4.1.2
------------------------------+---------------------------------------------
Reporter: anonymous | Owner:
Type: Bugs | Status: new
Milestone: To Be Determined | Component: None
Version: Boost 1.47.0 | Severity: Problem
Keywords: |
------------------------------+---------------------------------------------
Question about the boost sample program
I'm trying to compile the following code example:
#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
class gps_position {
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
ar & degrees;
ar & minutes;
ar & seconds;
}
int degrees;
int minutes;
float seconds;
public:
gps_position() {
degrees = 0;
minutes = 0;
seconds = 0.0;
};
gps_position(int d, int m, float s) : degrees(d), minutes(m),
seconds(s) {}
};
class bus_stop {
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
ar & latitude;
ar & longitude;
}
gps_position latitude;
gps_position longitude;
public:
bus_stop(){ }
bus_stop(const gps_position & lat_, const gps_position & long_) :
latitude(lat_), longitude(long_) { }
virtual ~bus_stop(){ }
};
int main() {
// create and open a character archive for output
std::ofstream ofs("busfile");
// create class instance of gps_position
const gps_position latitude(1, 2, 3.3f);
const gps_position longitude(4, 5, 6.6f);
bus_stop stop(latitude, longitude);
// save data to archive
{
boost::archive::text_oarchive oa(ofs);
// write class instance to archive
oa << stop;
}
// ... sometime later restore class instance of bus_stop to its
orginal state
bus_stop newstop;
{
// create and open an archive for input
std::ifstream ifs("busfile", std::ios::binary);
boost::archive::text_iarchive ia(ifs);
// read class state of bus_stop form archive
ia >> newstop;
}
return 0;
}
With the following command line:
g++ -o boostSample demo.cc -lboost_serialization
and it throws an compile error:
/usr/include/boost/archive/detail/oserializer.hpp: In function âvoid
boost::archive::save(Archive&, T&) [with Archive =
boost::archive::text_oarchive, T = bus_stop]â:
/usr/include/boost/archive/basic_text_oarchive.hpp:78: instantiated from
âvoid boost::archive::basic_text_oarchive<Archive>::save_override(T&, int)
[with T = bus_stop, Archive = boost::archive::text_oarchive]â
/usr/include/boost/archive/detail/interface_oarchive.hpp:78:
instantiated from âArchive&
boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with
T = bus_stop, Archive = boost::archive::text_oarchive]â
demo.cc:67: instantiated from here
/usr/include/boost/archive/detail/oserializer.hpp:567: error: invalid
application of âsizeofâ to incomplete type
âboost::STATIC_ASSERTION_FAILURE<false>
And the boost version is 1.33.1.
By the way, the OS version is redhat 5.6 .
Linux rhel5 2.6.18-238.el5 #1 SMP Sun Dec 19 14:24:47 EST 2010 i686 i686
i386 GNU/Linux
The gcc version is 4.1.2 .
g++ -v
Using built-in specs.
Target: i386-redhat-linux
config option: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-
checking=release --with-system-zlib --enable-__cxa_atexit --disable-
libunwind-exceptions --enable-libgcj-multifile --enable-
languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --disable-plugin --with-java-
home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic
--host=i386-redhat-linux
thread module: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)
But the same codes can be compiled well, no compile errors in the other
linux. Such as redhat4.3 and 6.0
How can I fix it?
Thank you.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/6107> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:07 UTC