[Boost-users] Flood of messages when building with boost_serialization

49 views
Skip to first unread message

Tony Camuso

unread,
Mar 4, 2015, 9:10:39 PM3/4/15
to boost...@lists.boost.org
Using Fedora 21 64 bit
gcc 4.9.2
Qt Creator 3.2.1
Qt 5.3.2

When I run make from the command line, all is well.

$ g++ -Wall -c kabi-serial.cpp -lboost_serialization

### no errors ###

Even if I build the whole project from the command line, there are no errors.

$ g++ -Wall -o kabi-parser -x c kabi.c -x c checksum.c -x c++ kabi-node.cpp -x c++ kabi-serial.cpp -lboost_serialization -lsparse


However, when I build it from Qt, I get the following compiler output.
I understand the "unused parameter" message, as I'm not using versioning
in my serialization implementation.

I haven't tried executing the serialization code, yet, but I wonder if it
will even execute properly, given the nature of the messages. The rest of
the code executes fine.

The serialization code is very simple and follows the messages.


20:38:17: Starting: "/usr/bin/make" kabi-serial.o
g++ -c -pipe -g -Wall -W -fPIE -I/home/tcamuso/Qt5.3.2/5.3/gcc_64/mkspecs/linux-g++ -I../../kabi -I../src/sparse -I../src/sparse -I. -o kabi-serial.o ../src/kabi-serial.cpp
In file included from ../src/kabi-serial.cpp:14:0:
../src/kabi-serial.h: In instantiation of 'void Cqnodelist::serialize(Archive&, unsigned int) [with Archive = boost::archive::text_oarchive]':
/usr/include/boost/serialization/access.hpp:118:9: required from 'static void boost::serialization::access::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::text_oarchive; T = Cqnodelist]'
/usr/include/boost/serialization/serialization.hpp:69:69: required from 'void boost::serialization::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::text_oarchive; T = Cqnodelist]'
/usr/include/boost/serialization/serialization.hpp:128:27: required from 'void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::text_oarchive; T = Cqnodelist]'
/usr/include/boost/archive/detail/oserializer.hpp:152:5: required from 'void boost::archive::detail::oserializer<Archive, T>::save_object_data(boost::archive::detail::basic_oarchive&, const void*) const [with Archive = boost::archive::text_oarchive; T = Cqnodelist]'
/usr/include/boost/archive/detail/oserializer.hpp:101:1: required from 'class boost::archive::detail::oserializer<boost::archive::text_oarchive, Cqnodelist>'
/usr/include/boost/archive/detail/oserializer.hpp:253:13: [ skipping 2 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
/usr/include/boost/archive/detail/oserializer.hpp:314:44: required from 'static void boost::archive::detail::save_non_pointer_type<Archive>::invoke(Archive&, T&) [with T = Cqnodelist; Archive = boost::archive::text_oarchive]'
/usr/include/boost/archive/detail/oserializer.hpp:525:24: required from 'void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive; T = Cqnodelist]'
/usr/include/boost/archive/detail/common_oarchive.hpp:69:40: required from 'void boost::archive::detail::common_oarchive<Archive>::save_override(T&, int) [with T = Cqnodelist; Archive = boost::archive::text_oarchive]'
/usr/include/boost/archive/basic_text_oarchive.hpp:80:9: required from 'void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = Cqnodelist; Archive = boost::archive::text_oarchive]'
/usr/include/boost/archive/detail/interface_oarchive.hpp:63:9: required from 'Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = Cqnodelist; Archive = boost::archive::text_oarchive]'
../src/kabi-serial.cpp:42:9: required from here
../src/kabi-serial.h:54:50: warning: unused parameter 'version' [-Wunused-parameter]
void serialize(Archive & ar, const unsigned int version)
^
20:38:17: The process "/usr/bin/make" exited normally.
20:38:17: Elapsed time: 00:00.

------------- source code ----------------------

#include <boost/serialization/vector.hpp>
#include <boost/archive/text_oarchive.hpp>

using namespace std;

namespace boost {
namespace serialization {

class Cqnodelist
{
public:
friend class boost::serialization::access;
Cqnodelist(){}
vector<int>qnodelist;

template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & qnodelist;
}
};

void kb_write_list ()
{
Cqnodelist ql;

ofstream ofs("kabi-list.dat");

{
boost::archive::text_oarchive oa(ofs);
oa << ql;
}
}

} // namespace serialization
} // namespace boost
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Steven Watanabe

unread,
Mar 4, 2015, 9:34:05 PM3/4/15
to boost...@lists.boost.org
AMDG

On 03/04/2015 06:59 PM, Tony Camuso wrote:
> <snip>
>
> However, when I build it from Qt, I get the following compiler output.
> I understand the "unused parameter" message, as I'm not using versioning
> in my serialization implementation.
>
> I haven't tried executing the serialization code, yet, but I wonder if it
> will even execute properly, given the nature of the messages. The rest of
> the code executes fine.
>

The warning is harmless. Just comment out the
parameter name to suppress it. The rest of the
message is part of the same warning. It's just
the template instantiation stack.

> The serialization code is very simple and follows the messages.
>
>
> 20:38:17: Starting: "/usr/bin/make" kabi-serial.o
> g++ -c -pipe -g -Wall -W -fPIE
> -I/home/tcamuso/Qt5.3.2/5.3/gcc_64/mkspecs/linux-g++ -I../../kabi
> -I../src/sparse -I../src/sparse -I. -o kabi-serial.o ../src/kabi-serial.cpp
> In file included from ../src/kabi-serial.cpp:14:0:
> <snip>
> ../src/kabi-serial.cpp:42:9: required from here
> ../src/kabi-serial.h:54:50: warning: unused parameter 'version'
> [-Wunused-parameter]
> void serialize(Archive & ar, const unsigned int version)
>

In Christ,
Steven Watanabe

Tony Camuso

unread,
Mar 5, 2015, 5:53:51 AM3/5/15
to boost...@lists.boost.org
Steven,

Thank you.

And even better to know that you're a brother in Christ!

Blessings,
Tony

Tony Camuso

unread,
Mar 5, 2015, 10:16:30 AM3/5/15
to boost...@lists.boost.org

Why is the compiler okay with ...
std::vector<int>intvec;

... but throws an error for ...
std::vector<int *>pintvec;

The error is ... /usr/include/boost/serialization/access.hpp:118: error: request for member 'serialize' in 't', which is of non-class type 'int' t.serialize(ar, file_version);

Tony Camuso

unread,
Mar 5, 2015, 7:29:59 PM3/5/15
to boost...@lists.boost.org
Very simple case. I just need to know what I'm doing wrong.

#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>

class foo
{
public:
int bar;
char *name;

template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
ar & name;
}
};

void write_foo(foo *f)
{
ofstream ofs("foo.txt");
{
boost::archive::text_oarchive oa(ofs);
oa << f;
}
}

The above fails to compile with the following error.

/usr/include/boost/serialization/access.hpp:118:9: error: request for member 'serialize' in 't', which is of non-class type 'char'
t.serialize(ar, file_version);

If I replace the char pointer "name" with the int "foo", it works.
Should I be using something other than boost::archive::text_oarchive?

Robert Ramey

unread,
Mar 6, 2015, 7:50:55 PM3/6/15
to boost...@lists.boost.org
Tony Camuso wrote
> Why is the compiler okay with ...
> std::vector
> <int>
> intvec;
> ... but throws an error for ...
> std::vector
> <int *>
> pintvec;

The answer can be found here:

</a> <http://>
http://stackoverflow.com/questions/19076299/how-do-i-serialize-a-class-containing-pointers-to-primitives

I concede that this should be added to the documentation. Feel free to
open a trac item to remind me of this.

So the solution is to wrap your int inside a class. This will give it a
unique type and distinguish from all the other int instances you don't
really want to track. Also you can use BOOST_SERIALIZATION to create a
wrapper.





--
View this message in context: http://boost.2283326.n4.nabble.com/Flood-of-messages-when-building-with-boost-serialization-tp4672684p4672804.html
Sent from the Boost - Users mailing list archive at Nabble.com.

Tony Camuso

unread,
Mar 6, 2015, 8:27:58 PM3/6/15
to boost...@lists.boost.org
On 03/06/2015 07:42 PM, Robert Ramey wrote:
> Tony Camuso wrote
>> Why is the compiler okay with ...
>> std::vector
>> <int>
>> intvec;
>> ... but throws an error for ...
>> std::vector
>> <int *>
>> pintvec;
>
> The answer can be found here:
>
> </a> <http://>
> http://stackoverflow.com/questions/19076299/how-do-i-serialize-a-class-containing-pointers-to-primitives
>
> I concede that this should be added to the documentation. Feel free to
> open a trac item to remind me of this.
>
> So the solution is to wrap your int inside a class. This will give it a
> unique type and distinguish from all the other int instances you don't
> really want to track. Also you can use BOOST_SERIALIZATION to create a
> wrapper.
>

Thanks, Robert.

Wasn't aware of the BOOST_SERIALIZATION macro. I'll look it up.

Another question. It seems that attempts to serialize containers of pointers
of any kind throw compiler errors. For example,

std::vector<string> str; // compiler is ok with serializing this

std::vector<string *> pstr; // compiler throws an error

The documentation gave me the impression that the serialization lib would
dereference the pointers correctly, and perform all the housekeeping around
that. Also got the impression that nothing special had to be done for the
deserialize step.

Is my reading comprehension off? :)

Thanks again for your help.

Robert Ramey

unread,
Mar 8, 2015, 8:42:18 PM3/8/15
to boost...@lists.boost.org
Tony Camuso wrote
> On 03/06/2015 07:42 PM, Robert Ramey wrote:
>> Tony Camuso wrote
>>> Why is the compiler okay with ...
>>> std::vector
>>>
> <int>
>>> intvec;
>>> ... but throws an error for ...
>>> std::vector
>>>
> <int *>
>>> pintvec;
>>
>> The answer can be found here:
>>
>>

> &lt;http://&gt;
>> http://stackoverflow.com/questions/19076299/how-do-i-serialize-a-class-containing-pointers-to-primitives
>>
>> I concede that this should be added to the documentation. Feel free to
>> open a trac item to remind me of this.

actually, I think I can do better than that. I got in the habit of adding a
layer of static asserts to trap cases where the user breaks some rule or
another. At the site of the trap, a comment in the code explains what on
has to do to fix it. Of course this is self defense so I don't have
continually answer the same questions over and over. Over the years as I get
a new question, I added traps like this. For some reason this question
hasn't been asked often enough to trigger my normal behavior. But I think I
can more or less easily implement this.

>> So the solution is to wrap your int inside a class. This will give it a
>> unique type and distinguish from all the other int instances you don't
>> really want to track. Also you can use BOOST_SERIALIZATION to create a
>> wrapper.

Note: it's BOOST_SERIALIZATION_STRONG_TYPEDEF. It's got it's own special
section in the manual.

But it only works for numeric types.

If you want to serialize a string pointer you'll have to snooker your system
like this:
>

Thanks, Robert.

Wasn't aware of the BOOST_SERIALIZATION macro. I'll look it up.

Another question. It seems that attempts to serialize containers of pointers
of any kind throw compiler errors. For example,

std::vector<string> str; // compiler is ok with serializing this

std::vector<string *> pstr; // compiler throws an error

The documentation gave me the impression that the serialization lib would
dereference the pointers correctly, and perform all the housekeeping around
that. Also got the impression that nothing special had to be done for the
deserialize step.

That's not correct - this problem occurs for all "primitive types". Look at
the
documentation on "serialization level". This basically means all C++
primitive
types + std::string. To handle std::string use:




> Is my reading comprehension off? :)

No, but you might want to do more of it.





--
View this message in context: http://boost.2283326.n4.nabble.com/Flood-of-messages-when-building-with-boost-serialization-tp4672684p4672857.html

Tony Camuso

unread,
Mar 8, 2015, 9:02:03 PM3/8/15
to boost...@lists.boost.org
You may want to post a FAQ for boost newbies. In your spare time, of course. :)
I have it working, now. I was confusing containers of pointers with pointers to
containers. The latter is supported, the former isn't, for reasons that become
obvious when you look at memory with a debugger.

Thanks for your help.

Regards,
Tony
Reply all
Reply to author
Forward
0 new messages