-
-
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
Duplicate symbols error happens while to_json/from_json method implemented inside entity definition header file #542
Labels
kind: question
solution: proposed fix
a fix for the issue has been proposed and waits for confirmation
Comments
Hi, there's two solutions to that:
|
Thanks for your answer. BTW, can it be a available solution to solve this problem by adding [static] before the function? |
nlohmann
added
the
solution: proposed fix
a fix for the issue has been proposed and waits for confirmation
label
Mar 31, 2017
Honestly I don't know if |
OK, Thanks. |
nlohmann
removed
the
solution: proposed fix
a fix for the issue has been proposed and waits for confirmation
label
Apr 7, 2017
Is it a good idea to add a short note to the documentation about this? |
nlohmann
added
the
solution: proposed fix
a fix for the issue has been proposed and waits for confirmation
label
Jun 25, 2019
jonathanmfung
added a commit
to jonathanmfung/leyval
that referenced
this issue
Dec 8, 2024
Consolidate to header-only. Must inline to_json per nlohmann/json#542 (comment). Also add basic JFProvider logic. Design: One global (main-created) rng that is passed-by-reference.
jonathanmfung
added a commit
to jonathanmfung/leyval
that referenced
this issue
Dec 8, 2024
Same change as previous with Agents (241efa3). Consolidate to header-only. Must inline to_json per nlohmann/json#542 (comment). Design: One global (main-created) rng that is passed-by-reference.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
kind: question
solution: proposed fix
a fix for the issue has been proposed and waits for confirmation
Can't upload the project file, so I try my best to make this clear...
I implemented the to_json/from_json methods inside the entity definition header file. Suppose the file called A.h, and include this file inside the main.cpp source file. I have another source file called B.h, it does nothing but include A.h and define a class called B. When I compile the whole project, I got a duplicate symbols error.
1>ConsoleApplication10.obj : error LNK2005: "void __cdecl from_json(class nlohmann::basic_json<class std::map,class std::vector,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,bool,__int64,unsigned __int64,double,class std::allocator,struct nlohmann::adl_serializer> const &,class A &)" (?from_json@@YAXABV?$basic_json@Vmap@std@@Vvector@2@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@_N_J_KNVallocator@2@Uadl_serializer@nlohmann@@@nlohmann@@AAVA@@@Z) 已经在 B.obj 中定义 1>ConsoleApplication10.obj : error LNK2005: "void __cdecl to_json(class nlohmann::basic_json<class std::map,class std::vector,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,bool,__int64,unsigned __int64,double,class std::allocator,struct nlohmann::adl_serializer> &,class A const &)" (?to_json@@YAXAAV?$basic_json@Vmap@std@@Vvector@2@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@_N_J_KNVallocator@2@Uadl_serializer@nlohmann@@@nlohmann@@ABVA@@@Z) 已经在 B.obj 中定义 1>D:\Documents\Visual Studio 2015\Projects\ConsoleApplication10\Debug\ConsoleApplication10.exe : fatal error LNK1169: 找到一个或多个多重定义的符号
And I solved this by set to_json/from_json as static methods. But, according to the tutorial, I don't have to do this. I don't know if this is a document error, or I use this in a wrong way.
Sorry for my poor English...
A.h
B.h
B.cpp
main file
The text was updated successfully, but these errors were encountered: