Cereal C++ error Unresolved External Symbol, cpp hpp issue?

199 Views Asked by At

I am new to cpp, coming from Java, so please be patient. I am trying to get the cereal library to work on a very basic test program before I add it into a larger program I am working on for fun. I am trying to serialize to json a Weather object, containing a string and an int.

hpp file:

#pragma once
using namespace std;
#include <iostream>

#include <cereal/archives/json.hpp>
#include <cereal/types/string.hpp>

class Weather
{
public:
    Weather(string status, int temp);

    
private:
    string status; 
    int temp;

    friend class cereal::access;
    template<class Archive>
    void serialize(Archive& archive);

};

cpp file:

#include "weather.h"

Weather::Weather(string status, int temp) {
    this->status = status;
    this->temp = temp;
}

template<class Archive>
void Weather::serialize(Archive& archive) {
    archive(CEREAL_NVP(this->temp),
            CEREAL_NVP(this->status)
    );
}

This object is called directly by main.

#include "main.h"
#include "weather.h"

#include <cereal/archives/json.hpp>
#include <fstream>

#include <iostream>
int main() {
    std::cout << "here";

    Weather today("clear", 10);

    std::ofstream os("data.json");
    cereal::JSONOutputArchive archive(os);

    {
        archive(CEREAL_NVP(today));
    }
}

I receive the following error on compile only:

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "private: void __cdecl Weather::serialize<class cereal::JSONOutputArchive>(class cereal::JSONOutputArchive &)" (??$serialize@VJSONOutputArchive@cereal@@@Weather@@AEAAXAEAVJSONOutputArchive@cereal@@@Z) referenced in function "public: static void __cdecl cereal::access::member_serialize<class cereal::JSONOutputArchive,class Weather>(class cereal::JSONOutputArchive &,class Weather &)" (??$member_serialize@VJSONOutputArchive@cereal@@VWeather@@@access@cereal@@SAXAEAVJSONOutputArchive@1@AEAVWeather@@@Z)   Serialize   C:\Users\97cwe\source\repos\Serialize\main.obj  1   

I can barely read the error, let alone make any sense of it. From what I have been able to read online about this error, it is something to with cereal not being able to find the serialize class. I don't know how to fix either.

Any help would be appreciated. Thank you

0

There are 0 best solutions below