[Serialization] Need help resolving problem putting serialization code into static library
All, I am hoping someone can help me resolve a problem I am having putting serialization code into a static library. If I am lucky, it will be simple user error. Here is a quick synopsis of the code: a.hpp class A { virtual ~A() { } ...} b.hpp class B : public A { virtual ~B() { } ... } with classes A and B both having the standard serialization functions defined in a.cpp and b.cpp respectively along with the necessary BOOST_CLASS_EXPORT statements. Now, compiling a single program like this works fine and the program is able to serialize objects of types A and B through pointers of type A without any problems. Life is good. g++ -o my_prog my_prog.cpp a.cpp b.cpp -lboost_serialization However, compiling a static library and then linking the same program like this produces a my_prog that gets an unregistered_class exception when trying to serialize an object of type B through a pointer of type A. Not what I expected because the only difference is in the linking phase where code is now coming from the library instead of the object files. g++ -o a.o -c a.cpp g++ -o b.o -c b.cpp ar cru a.o b.o libmine.a ranlib libmine.a g++ -o my_prog my_prog.cpp libmine.a -lboost_serialization Now, combining a.cpp and b.cpp and building the library produces a working program. Confusion reigns. g++ -o ab.o -c a.cpp b.cpp ar cru ab.o libmine.a ranlib libmine.a g++ -o my_prog my_prog.cpp libmine.a -lboost_serialization Any ideas would be greatly appreciated. I have tried several incantations, but I cannot make any headway. I am working under the assumptions that it has something do to with the initialization code difference between using the object files and the library. I am using boost 1.33.1 on intel OS X 10.4.8 with g++ in 64 bit mode. If it would be useful, I can run experiments in 32 bit mode or on Ubuntu, but I have yet to find any differences with this issue. Thanks, mark
participants (1)
-
Mark Melton