I am working with Visual Studio 2022, and I am facing several issues when trying to integrate jsoncpp
and C++/WinRT in my project. Here's the setup I'm using:
Package Management:
I installed jsoncpp and jsoncpp.windows via the NuGet Package Manager.
Includes:
I included jsoncpp using:
#include <json/json.h>
However, I am getting compilation errors related to allocator.h when trying to compile the project.
Severity Code Description File Line Suppression State Details
Error (active) E1696 cannot open source file "json/json.h" C:\Users\user\Documents\VS\WePublerEditor\WePublerEditorView.cpp 22
Error C2760 syntax error: 'static_cast' was unexpected here; expected 'type specifier' C:\Users\user\Documents\VS\WePublerEditor\packages\JsonCpp.Windows.1.9.2\build\native\include\json\allocator.h 52
Error C2760 syntax error: 'static_cast' was unexpected here; expected ')' C:\Users\user\Documents\VS\WePublerEditor\packages\JsonCpp.Windows.1.9.2\build\native\include\json\allocator.h 52
Error C3878 syntax error: unexpected token '<' following 'expression' C:\Users\user\Documents\VS\WePublerEditor\packages\JsonCpp.Windows.1.9.2\build\native\include\json\allocator.h 52
Error C2760 syntax error: ')' was unexpected here; expected ';' C:\Users\user\Documents\VS\WePublerEditor\packages\JsonCpp.Windows.1.9.2\build\native\include\json\allocator.h 52
Error C3878 syntax error: unexpected token ')' following 'expression-statement' C:\Users\user\Documents\VS\WePublerEditor\packages\JsonCpp.Windows.1.9.2\build\native\include\json\allocator.h 52
C++/WinRT Integration:
I also included C++/WinRT using the NuGet package and included headers like:
#include <Windows.h>
#include <winrt/base.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Data.Json.h>
#include <winrt/Windows.Foundation.h>
#include <iostream>
Error Messages:
Severity Code Description File Line Suppression State Details
Error C2059 syntax error: 'string' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 2152
Error C2091 function returns function C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 2152
Error C2802 static member 'operator new' has no formal parameters C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 2152
Error C2061 syntax error: identifier 'nothrow' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 5268
Error C2187 syntax error: 'raw' was unexpected here C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 5844
Error C3878 syntax error: unexpected token 'event_array' following 'braced-init-list' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 5844
Error C2760 syntax error: '<' was unexpected here; expected ';' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 5844
Error C3878 syntax error: unexpected token '<' following 'jump-statement' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 5844
Error C2760 syntax error: '>' was unexpected here; expected ';' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 5844
Error C2760 syntax error: '}' was unexpected here; expected ';' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 5844
Error C2187 syntax error: 'std' was unexpected here C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7817
Error C2760 syntax error: ')' was unexpected here; expected ';' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7817
Error C3878 syntax error: unexpected token ')' following 'expression-statement' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7817
Error C3878 syntax error: unexpected token ')' following 'statement' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7817
Error C3878 syntax error: unexpected token ')' following 'statement-seq' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7817
Error C2760 syntax error: ')' was unexpected here; expected '}' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7817
Error C3878 syntax error: unexpected token ')' following 'compound-statement' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7817
Error C3878 syntax error: unexpected token ')' following 'selection-statement' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7817
Error C3878 syntax error: unexpected token ')' following 'simple-type-specifier' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7819
Error C3878 syntax error: unexpected token '.' following 'simple-type-specifier' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7824
Error C3878 syntax error: unexpected token '.' following 'simple-declaration' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7824
Error C2760 syntax error: ')' was unexpected here; expected ';' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7824
Error C3878 syntax error: unexpected token ')' following 'expression-statement' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7824
Error C2065 'count_or_pointer': undeclared identifier C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7828
Error C3878 syntax error: unexpected token '->' following 'simple-type-specifier' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7830
Error C3878 syntax error: unexpected token '->' following 'simple-declaration' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7830
Error C3878 syntax error: unexpected token ')' following 'simple-type-specifier' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7831
Error C2760 syntax error: ')' was unexpected here; expected ';' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7831
Error C3878 syntax error: unexpected token ')' following 'expression-statement' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7831
Error C3878 syntax error: unexpected token ')' following 'statement' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7831
Error C3878 syntax error: unexpected token ')' following 'statement-seq' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7831
Error C2760 syntax error: ')' was unexpected here; expected '}' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7831
Error C3878 syntax error: unexpected token ')' following 'compound-statement' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7831
Error C3878 syntax error: unexpected token ')' following 'selection-statement' C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7831
Error C2065 'result': undeclared identifier C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7832
Error C2065 'count_or_pointer': undeclared identifier C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7835
Error C2065 'count_or_pointer': undeclared identifier C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7837
Error C2187 syntax error: '->' was unexpected here C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7840
Error C2065 'count_or_pointer': undeclared identifier C:\Users\user\Documents\VS\WePublerEditor\WePublerEditor\x64\Debug\Generated Files\winrt\base.h 7840
Error C2872 'IInspectable': ambiguous symbol C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\winrt\wrl\client.h 121
Error C2872 'IUnknown': ambiguous symbol C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\winrt\wrl\client.h 128
When trying to build the project, I am encountering about 45 syntax errors in base.h. These errors seem to be related to issues with jsoncpp or the integration of C++/WinRT.
Attempts to Solve:
I tried downloading the jsoncpp library directly from GitHub and adding it manually to the project, but the issue persists.
I've also checked and made sure all dependencies are correctly installed, but the errors remain.
Questions:
What could be causing these errors when integrating jsoncpp and C++/WinRT?
Is there a conflict between jsoncpp and C++/WinRT, or could this be related to a misconfiguration in my Visual Studio project?
Should I try reinstalling Visual Studio 2022, or is there another solution I can try to resolve this issue?
I would appreciate any help or suggestions to resolve these issues. Thank you in advance!
I encountered an error related to #include <json/json.h> in my project. After reviewing the comments(by @IInspectable), I followed the suggestion of moving the #include <json/json.h> to the top of my includes, and the error was resolved. Thanks for the help!