-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
json.hpp:8955: multiple definition of function that is not defined twice or more. #804
Comments
I cannot reproduce this with: // lib.hpp
#include "json.hpp"
using json = nlohmann::json;
namespace someNS {
std::string someFunction(json file) {
return file.dump(4);
}
} // main.cpp
#include "lib.hpp"
#include <iostream>
int main()
{
json j = {1,2,3};
std::cout << someNS::someFunction(j) << std::endl;
} and version 2.1.1. Running c++ -std=c++11 main.cpp -o main
./main yields [
1,
2,
3
] |
This looks a lot like a missing include guard, do you include |
@theodelrieu I have included it. |
Could you paste the contents of |
#include <SFML/Window.hpp>
#include "json.hpp"
using json = nlohmann::json;
namespace FB {
std::vector<sf::Vector2f> praseTeams(json file) {
std::vector<sf::Vector2f> ret;
unsigned int retPos = 0;
json tmp;
std::string itV;
for (json::iterator it = file.begin(); it != file.end(); ++it) {
itV = it.value();
tmp.parse(itV);
ret[retPos].x = tmp["x"];
ret[retPos].y = tmp["y"];
retPos++;
tmp = nullptr;
}
return ret;
}
} |
I guess this file is included multiple times, try to add a |
@theodelrieu Here is the code. The first one was older. #pragma once
#include <SFML/Window.hpp>
#include "json.hpp"
using json = nlohmann::json;
namespace FB {
std::vector<sf::Vector2f> praseTeams(json file) {
std::vector<sf::Vector2f> ret;
unsigned int retPos = 0;
json tmp;
std::string itV;
for (json::iterator it = file.begin(); it != file.end(); ++it) {
itV = it.value();
tmp.parse(itV);
ret[retPos].x = tmp["x"];
ret[retPos].y = tmp["y"];
retPos++;
tmp = 0;
}
return ret;
}
} |
Oh I didn't realize, it's very simple in fact. This has nothing to do with this library, you should not define a method in a header, unless:
|
Thank you! |
Json version 2.1.1
Any code in this form:
...Returns this error:
The text was updated successfully, but these errors were encountered: