Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7670785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:54:11+00:00 2026-05-31T15:54:11+00:00

I am experimenting with the boost serialization library and I’ve gotten most of it

  • 0

I am experimenting with the boost serialization library and I’ve gotten most of it working. The only problem is when i try to serialize an object that has separate .h and .cpp files. When i compile using this command:

g++ boostSerialize.cpp Class.cpp -lboost_serialization

i get this error:

/tmp/cc8kbW6J.o: In function `void boost::serialization::access::serialize<boost::archive::text_oarchive, Class>(boost::archive::text_oarchive&, Class&, unsigned int)':
boostSerialize.cpp:(.text._ZN5boost13serialization6access9serializeINS_7archive13text_oarchiveE5ClassEEvRT_RT0_j[void boost::serialization::access::serialize<boost::archive::text_oarchive, Class>(boost::archive::text_oarchive&, Class&, unsigned int)]+0x25): undefined reference to `void Class::serialize<boost::archive::text_oarchive>(boost::archive::text_oarchive&, unsigned int)'

this is what is in my .h:

#ifndef CLASS_H
#define CLASS_H
#include <iostream>
#include <string>
#include <boost/serialization/access.hpp>

using namespace std;

class Class{

    friend class boost::serialization::access;
    int a,b,c;
    string stringy;
    template<class Archive>
        void serialize(Archive &ar, const unsigned int);
    public:
        Class(int ab, int bb, int cb);

};
#endif

and my .cpp:

#include <iostream>
#include "Class.h"

using namespace std;

Class::Class(int ab, int bb, int cb){
    a = ab;
    b = bb;
    c = cb;
    stringy = "Text";
}

template<class Archive>
    void Class::serialize(Archive &ar, const unsigned int){
        ar & a & b & c & stringy;
    }

I tried instead putting everything only into a .cpp and including that and it worked fine, so i know that it is something to do with the .h inclusion. For some reason it is not finding the serialize function? I guess i could just use a .cpp instead of both but i really like organization and i would like to use this for a big project.
Any ideas? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:54:12+00:00Added an answer on May 31, 2026 at 3:54 pm

    Your problem is not with Boost.Serialization (as such), but that you are trying to separately compile a function template.

    Class::serialize is a function template, which means that it gets instantiated on the basis of the types of the template parameters that get passed to is. When compiling Class.cpp, the compiler does not know what types Class::serialize will be instantiated with, and so it cannot generate the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just been experimenting with the boost::function_types library recently, and I've come across a
I'm just experimenting with boost::pool to see if its a faster allocator for stuff
When experimenting with (embedded) Apache Derby DB, I noticed that a fresh database, with
Just experimenting and learning, and I know how to create a shared dictionary that
Is there a way to limit the header files that Boost.Build recursively scans for
Was experimenting with interface inheritance and found this: interface String{} interface Object{} interface Exception{}
In experimenting with this question I created an example that I utterly do not
I've been experimenting with a class that does pattern matching. My class looks something
Experimenting with Swing, I learnt that there are two ways of using JOptionPane and
I am experimenting with Boost.Range and the Boost Tuple. If I have a Tuple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.