How to use jsoncpp with Visual Studio 2022

2.6k Views Asked by At

I need my project to be able to use json format.

I was suggested this github : https://github.com/open-source-parsers/jsoncpp I have been trying to integrate it to my project for multiple hours and still cant find the issue.

I still get these errors on my include :

    #include <jsoncpp/json/json.h>

E1696 cannot open source file "jsoncpp/json/json.h"
C1083 Cannot open include file: 'jsoncpp/json/json.h'

I tried to go to C/C++ General->Additional Include Directories> to add the "jsoncpp-master\include" directory also tried "jsoncpp-master\include\json" directory also tried to add the .h and .cpp found in the repository directly.

I have also tried a multitude of other things but I'm not sure it would be relevant to list them all here.

I was not able to find instructions to use it with Visual Studio 2022 on their github either.

1

There are 1 best solutions below

1
Dark Sorrow On

Safest and most convenient way to use third party libraries is to use package manager like vcpkg

https://vcpkg.io/en/index.html

https://github.com/microsoft/vcpkg

Choose what build you want x86 or x64 and set default triplet in your environment variables

VCPKG_DEFAULT_TRIPLET

  1. x64-windows - DLL Build 64-bit windows
  2. x86-windows - DLL Build 32-bit windows
  3. x64-windows-static - Static Build 64-bit windows
  4. x86-windows-static - Static Build 32-bit windows

If you have added jsoncpp-master\include to C/C++ General->Additional Include Directories then you should use #include <json/json.h> instead of #include <jsoncpp/json/json.h>

Explanation : The compiler is looking inside the include directory. If you observer the file structure you can see json folder is located in the include directory and not jsoncpp.