ipkn / crow

Crow is very fast and easy to use C++ micro web framework (inspired by Python Flask)
BSD 3-Clause "New" or "Revised" License
7.43k stars 889 forks source link

Crow with nlohmann/json #381

Closed ezamosch closed 4 years ago

ezamosch commented 4 years ago

Hello. I am trying to use nlohmann/json lib in my Crow, but during compilation (MVS 2019) I got tons of errors:

1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3249,5): error C2144: syntax error: 'int' should be preceded by '}'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3249,12): error C2062: type 'int' unexpected
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3255,1): error C2143: syntax error: missing ';' before '}'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3270,37): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3270,37): error C2146: syntax error: missing ')' before identifier 'lhs'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3270,40): error C3646: 'lhs': unknown override specifier
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3270,40): error C2803: 'operator <' must have at least one formal parameter of class type
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3270,40): error C2805: binary 'operator <' has too few parameters
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3270,48): error C7525: inline variables require at least '/std:c++17'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3270,59): warning C4228: nonstandard extension used: qualifiers after comma in declarator list are ignored
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3270,56): error C2146: syntax error: missing ';' before identifier 'rhs'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3270,59): error C2059: syntax error: ')'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3270,61): error C2143: syntax error: missing ';' before 'noexcept'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3270,61): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3271,1): error C2143: syntax error: missing ';' before '{'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3271,1): error C2447: '{': missing function header (old-style formal list?)
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3284,1): error C2059: syntax error: '}'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3284,1): error C2143: syntax error: missing ';' before '}'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3288,1): error C2143: syntax error: missing ';' before '{'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3288,1): error C2447: '{': missing function header (old-style formal list?)
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3881,38): error C2589: 'int': illegal token on right side of '::'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3882,1): error C2993: 'unknown-type': is not a valid type for non-type template parameter '__formal'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3890,2): error C2913: explicit specialization; 'nlohmann::detail::external_constructor' is not a specialization of a class template
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3920,2): error C2913: explicit specialization; 'nlohmann::detail::external_constructor' is not a specialization of a class template
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3942,2): error C2913: explicit specialization; 'nlohmann::detail::external_constructor' is not a specialization of a class template
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3954,2): error C2913: explicit specialization; 'nlohmann::detail::external_constructor' is not a specialization of a class template
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3966,2): error C2913: explicit specialization; 'nlohmann::detail::external_constructor' is not a specialization of a class template
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(3978,2): error C2913: explicit specialization; 'nlohmann::detail::external_constructor' is not a specialization of a class template
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(4037,2): error C2913: explicit specialization; 'nlohmann::detail::external_constructor' is not a specialization of a class template
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(4069,2): error C2913: explicit specialization; 'nlohmann::detail::external_constructor' is not a specialization of a class template
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(4079,35): error C2589: 'int': illegal token on right side of '::'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(4079,5): error C2760: syntax error: unexpected token 'identifier', expected 'id-expression'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(4248,29): error C2039: 'from_json': is not a member of 'nlohmann'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(4230): message : see declaration of 'nlohmann'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(4269): message : see reference to class template instantiation 'nlohmann::adl_serializer<<unnamed-symbol>,<unnamed-symbol>>' being compiled
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(4250,21): error C2039: 'from_json': is not a member of 'nlohmann'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(4230): message : see declaration of 'nlohmann'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(4250,21): message : This diagnostic occurred in the compiler generated function 'unknown-type nlohmann::adl_serializer<<unnamed-symbol>,<unnamed-symbol>>::from_json(BasicJsonType &&,ValueType &) noexcept(<expr>)'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(4247,30): error C2039: 'from_json': is not a member of 'nlohmann'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(4230): message : see declaration of 'nlohmann'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(4247,30): message : This diagnostic occurred in the compiler generated function 'unknown-type nlohmann::adl_serializer<<unnamed-symbol>,<unnamed-symbol>>::from_json(BasicJsonType &&,ValueType &) noexcept(<expr>)'
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(4971,1): error C2632: 'bool' followed by 'int' is illegal
1>C:\Users\user\Desktop\C++ ServerTest\CrowServer\src\include\json.hpp(5059): message : see reference to class template instantiation 'nlohmann::json_sax<BasicJsonType>' being compiled
etc

Can somebody share experience how to plug nlohmann/json to my Crow project?

mrozigor commented 4 years ago

Can you include more info? Build script, source files, URL to repo?

ezamosch commented 4 years ago

@mrozigor, this is my project: https://github.com/lapleski/CrowServer

In Dao.h I create a data access object to oracle via OCILIB and there I include json.hpp (nlohmann/json). In Server.h I create a server object in which I use Dao class and include crow.h.

How to get build script from MVS I don't know(

mrozigor commented 4 years ago

I've built this. But first had to convert from MVS to CMake, then remove all dependencies to OCILIB. And then compiled project and it works OK. Maybe you incorrectly copied json.hpp file?

ezamosch commented 4 years ago

You are right. Looks like the problem is with OCILIB collisions. Anyway @mrozigor thank you. upd: I switched includes of json.hpp before ocilib.h and it compiled without errors.