Json: could this json lib work on windows?

Created on 24 Jul 2017  路  9Comments  路  Source: nlohmann/json

I download the zip on windows, and use cmake in minGW to generate .sln, then compile in VS2015, but I got more than 100 errors.

I saw this in readme:
Though it's 2016 already, the support for C++11 is still a bit sparse. Currently, the following compilers are known to work:
GCC 4.9 - 7.1 (and possibly later)
Clang 3.4 - 3.9 (and possibly later)
Microsoft Visual C++ 2015 / Build Tools 14.0.25123.0 (and possibly later)
Microsoft Visual C++ 2017 / Build Tools 15.1.548.43366 (and possibly later)

My VS2015 version is community 14.0.25431锛孖'm not sure where the problem is.
Thanks~

visual studio

Most helpful comment

@nlohmann Sorry for the delay!
I just ignored the errors reported in VS, now I'm using the lib refer to the readme, no problems til now. The stl-style api is easy to use. If I get problems in future, I'll ask for help again~
This issue could be closed. Thank you so much!

All 9 comments

Well the unit tests can be compiled and executed without errors, see https://ci.appveyor.com/project/nlohmann/json/build/2088/job/frx8pqcatlvi6goa

Could you provide more information?

if you want use this lib锛寉ou just only need download json.hpp锛宯ot the whole repository https://raw.githubusercontent.com/nlohmann/json/develop/src/json.hpp

thanks for your reply!
The errors reported are all from json_unit, I tried cmake again, found that I missed this information:

$ cmake ..
-- Building for: Visual Studio 14 2015
-- The CXX compiler identification is MSVC 19.0.24215.1
-- Check for working CXX compiler: E:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
-- Check for working CXX compiler: E:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- cotire 1.7.9 loaded.
-- CXX target json_unit cotired without unity build.
-- Configuring done
-- Generating done
-- Build files have been written to: E:/code/json/build

I don't know whether it's right til this step. Then I build the project in VS, the errors reported are these:

Severity Code Description Project File Line Suppression State
Error C2001 newline in constant json_unit E:\code\json\test\src\unit-class_parser.cpp 490
Error C2001 newline in constant json_unit E:\code\json\test\src\unit-class_parser.cpp 189
Error C2001 newline in constant json_unit E:\code\json\test\src\unit-class_parser.cpp 190
Error C1057 unexpected end of file in macro expansion json_unit E:\code\json\test\src\unit-class_parser.cpp 189
Error C2001 newline in constant json_unit E:\code\json\test\src\unit-udt.cpp 115
Error C2001 newline in constant json_unit E:\code\json\test\src\unit-udt.cpp 202
Error C2988 unrecognizable template declaration/definition json_unit E:\code\json\test\src\unit-udt.cpp 339
Error C2143 syntax error: missing ';' before '<' json_unit E:\code\json\test\src\unit-udt.cpp 339
Error C2059 syntax error: '<' json_unit E:\code\json\test\src\unit-udt.cpp 339
Error C2065 'T': undeclared identifier json_unit E:\code\json\test\src\unit-udt.cpp 339
Error C2923 'std::shared_ptr': 'T' is not a valid template type argument for parameter '_Ty' json_unit E:\code\json\test\src\unit-udt.cpp 339
Error C2143 syntax error: missing ';' before '{' json_unit E:\code\json\test\src\unit-udt.cpp 340
Error C2447 '{': missing function header (old-style formal list?) json_unit E:\code\json\test\src\unit-udt.cpp 340
Error C2039 'person': is not a member of 'udt::udt' json_unit E:\code\json\test\src\unit-udt.cpp 387
Error C2039 'person': is not a member of 'udt::udt' json_unit E:\code\json\test\src\unit-udt.cpp 392
Error C3083 'country': the symbol to the left of a '::' must be a type json_unit E:\code\json\test\src\unit-udt.cpp 392
Error C2039 'russia': is not a member of 'udt::udt' json_unit E:\code\json\test\src\unit-udt.cpp 392
Error C2065 'russia': undeclared identifier json_unit E:\code\json\test\src\unit-udt.cpp 392
Error C2039 'person': is not a member of 'udt::udt' json_unit E:\code\json\test\src\unit-udt.cpp 396
Error C2039 'person': is not a member of 'udt::udt' json_unit E:\code\json\test\src\unit-udt.cpp 401
Error C3536 'person': cannot be used before it is initialized json_unit E:\code\json\test\src\unit-udt.cpp 401
Error C3083 'country': the symbol to the left of a '::' must be a type json_unit E:\code\json\test\src\unit-udt.cpp 401
Error C2039 'russia': is not a member of 'udt::udt' json_unit E:\code\json\test\src\unit-udt.cpp 401
Error C2065 'russia': undeclared identifier json_unit E:\code\json\test\src\unit-udt.cpp 401
Error C2064 term does not evaluate to a function taking 1 arguments json_unit E:\code\json\test\src\unit-udt.cpp 401
Error C2039 'person': is not a member of 'udt::udt' json_unit E:\code\json\test\src\unit-udt.cpp 404
Error C2923 'std::shared_ptr': 'person' is not a valid template type argument for parameter '_Ty' json_unit E:\code\json\test\src\unit-udt.cpp 404
Error C2672 'nlohmann::basic_json::get': no matching overloaded function found json_unit E:\code\json\test\src\unit-udt.cpp 404
Error C3206 'nlohmann::basic_json::get': invalid template argument for 'PointerType', missing template argument list on class template 'std::shared_ptr' json_unit E:\code\json\test\src\unit-udt.cpp 404
Error C3206 'nlohmann::basic_json::get': invalid template argument for 'ValueTypeCV', missing template argument list on class template 'std::shared_ptr' json_unit E:\code\json\test\src\unit-udt.cpp 404
Error C3206 'nlohmann::basic_json::get': invalid template argument for 'BasicJsonType', missing template argument list on class template 'std::shared_ptr' json_unit E:\code\json\test\src\unit-udt.cpp 404
Error C3536 'optPerson': cannot be used before it is initialized json_unit E:\code\json\test\src\unit-udt.cpp 405
Error C2100 illegal indirection json_unit E:\code\json\test\src\unit-udt.cpp 406
Error C2446 '<=': no conversion from 'int' to 'Catch::ResultBuilder' json_unit E:\code\json\test\src\unit-udt.cpp 406
Error C2228 left of '.endExpression' must have class/struct/union json_unit E:\code\json\test\src\unit-udt.cpp 406
Error C2039 'person': is not a member of 'udt::udt' json_unit E:\code\json\test\src\unit-udt.cpp 409
Error C2923 'std::shared_ptr': 'person' is not a valid template type argument for parameter '_Ty' json_unit E:\code\json\test\src\unit-udt.cpp 409
Error C2672 'nlohmann::basic_json::get': no matching overloaded function found json_unit E:\code\json\test\src\unit-udt.cpp 409
Error C3206 'nlohmann::basic_json::get': invalid template argument for 'PointerType', missing template argument list on class template 'std::shared_ptr' json_unit E:\code\json\test\src\unit-udt.cpp 409
Error C3206 'nlohmann::basic_json::get': invalid template argument for 'ValueTypeCV', missing template argument list on class template 'std::shared_ptr' json_unit E:\code\json\test\src\unit-udt.cpp 409
Error C3206 'nlohmann::basic_json::get': invalid template argument for 'BasicJsonType', missing template argument list on class template 'std::shared_ptr' json_unit E:\code\json\test\src\unit-udt.cpp 409
Error C2039 'person': is not a member of 'udt::udt' json_unit E:\code\json\test\src\unit-udt.cpp 502
Error C2039 'person': is not a member of 'udt::udt' json_unit E:\code\json\test\src\unit-udt.cpp 507
Error C3083 'country': the symbol to the left of a '::' must be a type json_unit E:\code\json\test\src\unit-udt.cpp 507
Error C2039 'russia': is not a member of 'udt::udt' json_unit E:\code\json\test\src\unit-udt.cpp 507
Error C2065 'russia': undeclared identifier json_unit E:\code\json\test\src\unit-udt.cpp 507
Error C2039 'person': is not a member of 'udt::udt' json_unit E:\code\json\test\src\unit-udt.cpp 511
Error C2039 'person': is not a member of 'udt::udt' json_unit E:\code\json\test\src\unit-udt.cpp 516
Error C3536 'person': cannot be used before it is initialized json_unit E:\code\json\test\src\unit-udt.cpp 516
Error C3083 'country': the symbol to the left of a '::' must be a type json_unit E:\code\json\test\src\unit-udt.cpp 516
Error C2039 'russia': is not a member of 'udt::udt' json_unit E:\code\json\test\src\unit-udt.cpp 516
Error C2065 'russia': undeclared identifier json_unit E:\code\json\test\src\unit-udt.cpp 516
Error C2064 term does not evaluate to a function taking 1 arguments json_unit E:\code\json\test\src\unit-udt.cpp 516
Error C2039 'person': is not a member of 'udt::udt' json_unit E:\code\json\test\src\unit-udt.cpp 519
Error C2923 'std::unique_ptr': 'person' is not a valid template type argument for parameter '_Ty' json_unit E:\code\json\test\src\unit-udt.cpp 519
Error C3203 'default_delete': unspecialized class template can't be used as a template argument for template parameter '_Dx', expected a real type json_unit E:\code\json\test\src\unit-udt.cpp 519
Error C2672 'nlohmann::basic_json::get': no matching overloaded function found json_unit E:\code\json\test\src\unit-udt.cpp 519
Error C3206 'nlohmann::basic_json::get': invalid template argument for 'PointerType', missing template argument list on class template 'std::unique_ptr' json_unit E:\code\json\test\src\unit-udt.cpp 519
Error C3206 'nlohmann::basic_json::get': invalid template argument for 'ValueTypeCV', missing template argument list on class template 'std::unique_ptr' json_unit E:\code\json\test\src\unit-udt.cpp 519
Error C3206 'nlohmann::basic_json::get': invalid template argument for 'BasicJsonType', missing template argument list on class template 'std::unique_ptr' json_unit E:\code\json\test\src\unit-udt.cpp 519
Error C3536 'optPerson': cannot be used before it is initialized json_unit E:\code\json\test\src\unit-udt.cpp 520
Error C2100 illegal indirection json_unit E:\code\json\test\src\unit-udt.cpp 521
Error C2446 '<=': no conversion from 'int' to 'Catch::ResultBuilder' json_unit E:\code\json\test\src\unit-udt.cpp 521
Error C2228 left of '.endExpression' must have class/struct/union json_unit E:\code\json\test\src\unit-udt.cpp 521
Error C2039 'person': is not a member of 'udt::udt' json_unit E:\code\json\test\src\unit-udt.cpp 524
Error C2923 'std::unique_ptr': 'person' is not a valid template type argument for parameter '_Ty' json_unit E:\code\json\test\src\unit-udt.cpp 524
Error C3203 'default_delete': unspecialized class template can't be used as a template argument for template parameter '_Dx', expected a real type json_unit E:\code\json\test\src\unit-udt.cpp 524
Error C2672 'nlohmann::basic_json::get': no matching overloaded function found json_unit E:\code\json\test\src\unit-udt.cpp 524
Error C3206 'nlohmann::basic_json::get': invalid template argument for 'PointerType', missing template argument list on class template 'std::unique_ptr' json_unit E:\code\json\test\src\unit-udt.cpp 524
Error C3206 'nlohmann::basic_json::get': invalid template argument for 'ValueTypeCV', missing template argument list on class template 'std::unique_ptr' json_unit E:\code\json\test\src\unit-udt.cpp 524
Error C3206 'nlohmann::basic_json::get': invalid template argument for 'BasicJsonType', missing template argument list on class template 'std::unique_ptr' json_unit E:\code\json\test\src\unit-udt.cpp 524
Error C2039 'basic_json': is not a member of 'udt::nlohmann' json_unit E:\code\json\test\src\unit-udt.cpp 643
Error C2061 syntax error: identifier 'basic_json' json_unit E:\code\json\test\src\unit-udt.cpp 643
Error C2065 'custom_json': undeclared identifier json_unit E:\code\json\test\src\unit-udt.cpp 648
Error C2146 syntax error: missing ';' before identifier 'j' json_unit E:\code\json\test\src\unit-udt.cpp 648
Error C2065 'j': undeclared identifier json_unit E:\code\json\test\src\unit-udt.cpp 648
Error C2065 'j': undeclared identifier json_unit E:\code\json\test\src\unit-udt.cpp 650
Error C2228 left of '.get' must have class/struct/union json_unit E:\code\json\test\src\unit-udt.cpp 650
Error C2059 syntax error: ')' json_unit E:\code\json\test\src\unit-udt.cpp 650
Error C3536 'p2': cannot be used before it is initialized json_unit E:\code\json\test\src\unit-udt.cpp 652
Error C2678 binary '==': no operator found which takes a left-hand operand of type 'udt::udt::small_pod' (or there is no acceptable conversion) json_unit E:\code\json\test\src\unit-udt.cpp 652
Error C2065 'custom_json': undeclared identifier json_unit E:\code\json\test\src\unit-udt.cpp 655
Error C2146 syntax error: missing ';' before identifier 'j2' json_unit E:\code\json\test\src\unit-udt.cpp 655
Error C2065 'j2': undeclared identifier json_unit E:\code\json\test\src\unit-udt.cpp 655
Error C2065 'j2': undeclared identifier json_unit E:\code\json\test\src\unit-udt.cpp 656
Error C2228 left of '.get' must have class/struct/union json_unit E:\code\json\test\src\unit-udt.cpp 656
Error C2059 syntax error: ')' json_unit E:\code\json\test\src\unit-udt.cpp 656
Error C3536 'np2': cannot be used before it is initialized json_unit E:\code\json\test\src\unit-udt.cpp 657
Error C2679 binary '==': no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion) json_unit E:\code\json\test\src\unit-udt.cpp 657
Error C2039 'basic_json': is not a member of 'udt::nlohmann' json_unit E:\code\json\test\src\unit-udt.cpp 663
Error C2061 syntax error: identifier 'basic_json' json_unit E:\code\json\test\src\unit-udt.cpp 663
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int json_unit E:\code\json\test\src\unit-udt.cpp 668
Error C2143 syntax error: missing ',' before '&' json_unit E:\code\json\test\src\unit-udt.cpp 668
Error C2061 syntax error: identifier 'custom_json' json_unit E:\code\json\test\src\unit-udt.cpp 674
Error C2039 'json': is not a member of 'udt::nlohmann' json_unit E:\code\json\test\src\unit-udt.cpp 683
Error C2039 'person': is not a member of 'udt::udt' json_unit E:\code\json\test\src\unit-udt.cpp 685
Error C3083 'country': the symbol to the left of a '::' must be a type json_unit E:\code\json\test\src\unit-udt.cpp 685
Error C2039 'france': is not a member of 'udt::udt' json_unit E:\code\json\test\src\unit-udt.cpp 685
Error C2065 'france': undeclared identifier json_unit E:\code\json\test\src\unit-udt.cpp 685
Error C2065 'custom_json': undeclared identifier json_unit E:\code\json\test\src\unit-udt.cpp 688
Error C2146 syntax error: missing ';' before identifier 'cj' json_unit E:\code\json\test\src\unit-udt.cpp 688
Error C2065 'cj': undeclared identifier json_unit E:\code\json\test\src\unit-udt.cpp 688
Error C2065 'cj': undeclared identifier json_unit E:\code\json\test\src\unit-udt.cpp 690
Error C2228 left of '.dump' must have class/struct/union json_unit E:\code\json\test\src\unit-udt.cpp 690
Error C2228 left of '.endExpression' must have class/struct/union json_unit E:\code\json\test\src\unit-udt.cpp 690
Error C2039 'person': is not a member of 'udt::udt' json_unit E:\code\json\test\src\unit-udt.cpp 692
Error C1003 error count exceeds 100; stopping compilation json_unit E:\code\json\test\src\unit-udt.cpp 692
Warning C4503 'nlohmann::detail::conjunction>,nlohmann::detail::negation>,nlohmann::detail::negation,std::allocator>,CompatibleArrayType>>,nlohmann::detail::negation::create::>>>,nlohmann::detail::has_value_type,nlohmann::detail::has_iterator>': decorated name length exceeded, name was truncated json_unit E:\code\json\test\src\unit-algorithms.cpp 1
Warning C4503 'std::conditional>,nlohmann::detail::negation,std::allocator>,CompatibleArrayType>>,nlohmann::detail::negation::create::>>>,nlohmann::detail::has_value_type,nlohmann::detail::has_iterator>,B1>': decorated name length exceeded, name was truncated json_unit E:\code\json\test\src\unit-algorithms.cpp 1
Warning C4503 'nlohmann::detail::conjunction>,nlohmann::detail::negation>,nlohmann::detail::negation,std::allocator>,CompatibleArrayType>>,nlohmann::detail::negation::create::>>>,nlohmann::detail::has_value_type,nlohmann::detail::has_iterator>': decorated name length exceeded, name was truncated json_unit E:\code\json\test\src\unit-algorithms.cpp 320
Warning C4503 'nlohmann::detail::conjunction>,nlohmann::detail::negation,std::allocator>,CompatibleArrayType>>,nlohmann::detail::negation::create::>>>,nlohmann::detail::has_value_type,nlohmann::detail::has_iterator>': decorated name length exceeded, name was truncated json_unit E:\code\json\test\src\unit-algorithms.cpp 320
Warning C4503 'std::conditional>,nlohmann::detail::negation,std::allocator>,CompatibleArrayType>>,nlohmann::detail::negation::create::>>>,nlohmann::detail::has_value_type,nlohmann::detail::has_iterator>,B1>': decorated name length exceeded, name was truncated json_unit E:\code\json\test\src\unit-algorithms.cpp 320
Warning C4503 'std::conditional,std::allocator>,CompatibleArrayType>>,nlohmann::detail::negation,std::unique_ptr::create::>>>,nlohmann::detail::has_value_type,nlohmann::detail::has_iterator>,B1>': decorated name length exceeded, name was truncated json_unit E:\code\json\test\src\unit-algorithms.cpp 320
Warning C4819 The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss json_unit E:\code\json\test\src\unit-class_parser.cpp 1
Warning C4244 'initializing': conversion from 'double' to 'float', possible loss of data json_unit E:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\utility 172
Warning C4996 'nlohmann::basic_json::operator <<': was declared deprecated json_unit E:\code\json\test\src\unit-deserialization.cpp 71
Warning C4996 'nlohmann::basic_json::operator <<': was declared deprecated json_unit E:\code\json\test\src\unit-deserialization.cpp 119
Warning C4996 'nlohmann::basic_json::operator <<': was declared deprecated json_unit E:\code\json\test\src\unit-deserialization.cpp 120
Warning C4996 'nlohmann::basic_json::operator >>': was declared deprecated json_unit E:\code\json\test\src\unit-serialization.cpp 71
Warning C4996 'nlohmann::basic_json::operator >>': was declared deprecated json_unit E:\code\json\test\src\unit-serialization.cpp 80
Warning C4996 'nlohmann::basic_json::operator >>': was declared deprecated json_unit E:\code\json\test\src\unit-serialization.cpp 91
Warning C4819 The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss json_unit E:\code\json\test\src\unit-udt.cpp 1

thanks for your attention!

@itviewer thank you for your help!
I haven't used this kind of lib before so I cmake, compile the project as usual. Then is it all right that I ignore these errors and use the header file directly?

@PinkGabriel yes, all other files only used for develop or test json.hpp锛寉ou only need json.hpp to develop your Project

@itviewer thanks, I'll follow the readme and have a try.

Any news on this?

@nlohmann Sorry for the delay!
I just ignored the errors reported in VS, now I'm using the lib refer to the readme, no problems til now. The stl-style api is easy to use. If I get problems in future, I'll ask for help again~
This issue could be closed. Thank you so much!

Thanks for checking back!

Was this page helpful?
0 / 5 - 0 ratings