Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

cannot include json.hpp from more than one cpp file due to multiply defined symbols #4

Open
frans-fuerst opened this issue Dec 20, 2015 · 5 comments

Comments

@frans-fuerst
Copy link

including json.hpp in multiple cpp files leads to linker errors:

file1.o: In function `json::Array()':
json.hpp:410: multiple definition of `json::Array()'
file2.o:json.hpp:410: first defined here
file1.o: In function `json::Object()':
json.hpp:421: multiple definition of `json::Object()'

Compiler is gcc 5.1.1 building on Fedora 22

@eduard739
Copy link

i have the same problem. tried everything. it wont go away

@eduard739
Copy link

fixed the issue: although i created a cpp file, and i do not know how to developer wanted the lib to be(i think it meant to be only hpp file) so i will not commit. all you have to do it to take JSON::load implementation and put it in a cpp file. and add template <typename... T> above the functions:
JSON Object, operator<< and JSON Array

@nbsdx
Copy link
Owner

nbsdx commented Feb 7, 2017

Not gonna lie, I totally forgot this issue was here.

I have to rewrite the parser because of #8 so I'll likely fix this at the same time. Things need to be restructured anyways.

Unfortunately it might be a little while until I can fix it, I'm in the middle of changing jobs and moving so I'm kinda swamped.

@jyesselm
Copy link

jyesselm commented Jan 1, 2018

@eduard739 thank you! totally solved my problem

abrock added a commit to abrock/SimpleJSON that referenced this issue Mar 1, 2018
leventeBajczi added a commit to leventeBajczi/SimpleJSON that referenced this issue Apr 19, 2018
As issue nbsdx#4 points out, json.hpp can not be included from multiple files. Adding `inline` in front of non-template functions fix this issue without having to introduce a separate .cpp file.
@Amazonasmann
Copy link

Just a reminder.. I started using this lib and now I am encountering the same problem!

veelion added a commit to veelion/wenet that referenced this issue Nov 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants