Opened 11 years ago

Closed 11 years ago

#6107 closed Bugs (wontfix)

Boost sample source code cant compile .boost1.33.1 and gcc4.1.2

Reported by: anonymous Owned by: Robert Ramey
Milestone: To Be Determined Component: serialization
Version: Severity: Problem
Keywords: Cc:

Description

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.

Change History (2)

comment:1 by mtloveft@…, 11 years ago

Component: Noneserialization
Owner: set to Robert Ramey
Version: Boost 1.47.0

comment:2 by Robert Ramey, 11 years ago

Resolution: wontfix
Status: newclosed

I'm going to assume that this is particular the the compiler version. Try upgrading to a more recent version of GCC. Since I don't have the the setup to reproduce this, I'll have to say I don't see what I can do about this. If you have a tested patch, I would be willing to look at it. Otherwise I'm going to have to close this ticket. Sorry I couldn't be more helpful.

Robert Ramey

Note: See TracTickets for help on using tickets.