Skip to content

Instantly share code, notes, and snippets.

@OXPHOS
Last active July 12, 2016 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OXPHOS/03d20339c3cf36a7a5cc11e3ab3fd7fe to your computer and use it in GitHub Desktop.
Save OXPHOS/03d20339c3cf36a7a5cc11e3ab3fd7fe to your computer and use it in GitHub Desktop.
#include "base.h"
using namespace std;
base::base()
{
a = 3;
b = 2;
}
int base::add(int x, int y)
{
return x + y;
}
template<class Archive>
void base::save(Archive & archive) const
{
archive(a, b);
}
template<class Archive>
void base::load(Archive & archive)
{
archive(a, b);
}
#define CEREAL_SAVE_FUNCTION_NAME cereal_save
#define CEREAL_LOAD_FUNCTION_NAME cereal_load
#ifndef base_h_
#define base_h_
using namespace std;
class base
{
public:
int a, b;
base();
int add(int x, int y);
template<class Archive>
void save(Archive & archive) const;
template<class Archive>
void load(Archive & archive);
};
#endif
#undef CEREAL_SAVE_FUNCTION_NAME
#undef CEREAL_LOAD_FUNCTION_NAME
#include "base.h"
using namespace std;
class derived : public base
{
public:
int c, d;
derived() : base()
{
c = 0;
d = -1;
}
};
Mac148934:test2 zora$ g++ -c -std=c++11 base.cpp
Mac148934:test2 zora$ g++ -c -std=c++11 test.cpp
Mac148934:test2 zora$ g++ -std=c++11 base.o test.o -o test
Undefined symbols for architecture x86_64:
"void base::serialize<cereal::JSONOutputArchive>(cereal::JSONOutputArchive&) const", referenced from:
decltype(fp0.serialize(fp)) cereal::access::member_serialize<cereal::JSONOutputArchive, derived>(cereal::JSONOutputArchive&, derived&) in test.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
#include "cereal/archives/json.hpp"
#include <fstream>
#include "derived.h"
using namespace std;
int main()
{
derived d;
{
std::ofstream os("cereatltest_save.cereal");
cereal::JSONOutputArchive archive(os);
archive(d);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment