Linker error on basic example, I am missing something?
edgs1alu opened this issue · comments
edgs1alu commented
I'm trying to build the basic examples using the header-only version of the library, I've tried to compile the standard containers example of usage.md:
#include <iostream>
#include "ThorSerialize/SerUtil.h"
#include "ThorSerialize/JsonThor.h"
int main()
{
using ThorsAnvil::Serialize::jsonExporter;
using ThorsAnvil::Serialize::PrinterInterface;
std::vector<int> data {1,2,3,4,5};
std::cout << ThorsAnvil::Serialize::jsonExporter(data, PrinterInterface::OutputType::Stream);
}
I've cloned the header-only branch this way:
git clone --single-branch --branch header-only https://github.com/Loki-Astari/ThorsSerializer.git
and when I run
g++ std=c++17 -IThorsSerializer main.cpp
I get this linker error
/usr/bin/ld: /tmp/cc8URBB7.o: warning: relocation against `_ZTVN10ThorsAnvil9Serialize11JsonPrinterE' in read-only section `.text._ZN10ThorsAnvil9Serialize11JsonPrinterD2Ev[_ZN10ThorsAnvil9Serialize11JsonPrinterD5Ev]'
/usr/bin/ld: /tmp/cc8URBB7.o: in function `main':
main.cpp:(.text+0xa7): undefined reference to `ThorsAnvil::Serialize::defaultPolymorphicMarker[abi:cxx11]'
/usr/bin/ld: /tmp/cc8URBB7.o: in function `ThorsAnvil::Serialize::JsonPrinter::~JsonPrinter()':
main.cpp:(.text._ZN10ThorsAnvil9Serialize11JsonPrinterD2Ev[_ZN10ThorsAnvil9Serialize11JsonPrinterD5Ev]+0xf): undefined reference to `vtable for ThorsAnvil::Serialize::JsonPrinter'
/usr/bin/ld: /tmp/cc8URBB7.o: in function `ThorsAnvil::Serialize::operator<<(std::ostream&, ThorsAnvil::Serialize::Exporter<ThorsAnvil::Serialize::Json, std::vector<int, std::allocator<int> > > const&)':
main.cpp:(.text._ZN10ThorsAnvil9SerializelsERSoRKNS0_8ExporterINS0_4JsonESt6vectorIiSaIiEEEE[_ZN10ThorsAnvil9SerializelsERSoRKNS0_8ExporterINS0_4JsonESt6vectorIiSaIiEEEE]+0x61): undefined reference to `ThorsAnvil::Serialize::JsonPrinter::
JsonPrinter(std::ostream&, ThorsAnvil::Serialize::PrinterInterface::PrinterConfig)'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
I am missing something?
Calum H. commented
Im encountering this too - no clue why
Loki Astari commented
Try this:
#include <iostream>
#include "ThorSerialize/SerUtil.h"
#include "ThorSerialize/JsonThor.h"
// I added these.
// I have not used the header version much (just some testing).
// If you have some ideas to make it easier to use please let me know.
#include "ThorSerialize/JsonPrinter.source"
#include "ThorSerialize/ThorsSerializerUtil.source"
int main()
{
using ThorsAnvil::Serialize::jsonExporter;
using ThorsAnvil::Serialize::PrinterInterface;
std::vector<int> data {1,2,3,4,5};
std::cout << ThorsAnvil::Serialize::jsonExporter(data, PrinterInterface::OutputType::Stream);
}
Calum H. commented
Thank you
Loki Astari commented
Have massively cleaned up the header only version.