Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2007-11-29 11:27:04


This is a C++ syntax issue.

The first example explicitly instantiates the serialize declaration without specifying its implementation
which leads to an undefined symbol. just use:

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

and the appropriate code wil be instantiated if and only if it is actually invoked.

Robert Ramey

  "Oliver Kania" <kania.oliver_at_[hidden]> wrote in message news:1262c4ee0711290739x12408875u39e54bbe9effb093_at_mail.gmail.com...
  Hello !

  When linking a program that consists only of main.cpp with a library that serializes
  a class "Palo Cllient" I get the following message (sry for the mess):

  ==================================================
   error LNK2019: unresolved external symbol "private: void __thiscall jedox::palo::PaloClient::serialize<class boost::archive::text_oarchive>(class boost::archive::text_oarchive &,unsigned int)" (??$serialize@ Vtext_oarchive_at_archive@boost@@@PaloClient_at_palo@jedox@@AAEXAAVtext_oarchive_at_archive@boost@@I_at_Z) referenced in function "public: static void __cdecl boost::serialization::access::serialize<class boost::archive::text_oarchive,class jedox::palo::PaloClient>(class boost::archive::text_oarchive &,class jedox::palo::PaloClient &,unsigned int)" (??$serialize@ Vtext_oarchive_at_archive@boost@@VPaloClient_at_palo@jedox@@@access_at_serialization@boost@@SAXAAVtext_oarchive_at_archive@2_at_AAVPaloClient@palo_at_jedox@@I_at_Z)
  ==================================================

  This happens even though I do NOT explicitly serialize anything.
  Main.cpp includes:

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

  For the class PaloClient, I do use the Pimpl idiom and serialize as it is recommended
  in the documentation:

  PaloClient.cpp:

  --------------------------------------------------------------

  #include <boost/archive/text_oarchive.hpp>
  #include <boost/archive/text_iarchive.hpp>
  #include <boost/serialization/scoped_ptr.hpp>

  ....

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

  template void PaloClient::serialize<boost::archive::text_iarchive>(
              boost::archive::text_iarchive & ar,
              const unsigned int file_version
              );

          template void PaloClient::serialize<boost::archive::text_oarchive>(
              boost::archive::text_oarchive & ar,
              const unsigned int file_version
              );
  ------------------------------------------------------------------------

  Now, when I change this to

          void PaloClient::serialize(boost::archive::text_iarchive & ar, const unsigned int file_version) {
              ar & m_PaloClientImpl;
          }

          void PaloClient::serialize (boost::archive::text_oarchive & ar, const unsigned int file_version) {
                  ar & m_PaloClientImpl;
          }

  The linkage error disappears. I guess this is a Visual C++ compiler problem but
  I wanted to post this in case someone else has similar problems.

  Kind regards, Oliver

  PS: Thanks for this great serialization library, it saved me many weeks of programming.

------------------------------------------------------------------------------

  _______________________________________________
  Boost-users mailing list
  Boost-users_at_[hidden]
  http://lists.boost.org/mailman/listinfo.cgi/boost-users



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net