0

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.

3
  • 1
    If you've told VS to look in jsoncpp-master\include, the include should look something like #include <json/json.h>. Rational: json.h is in include/json Commented Feb 4, 2023 at 1:24
  • Oh so the jsoncpp/json in my include is the rest of the path to locate the .h? If I had added "jsoncpp-master" in the Additional Include Directories then I would have included it like so : #include <jsoncpp/json/json.h> Commented Feb 4, 2023 at 1:31
  • If you pointed VS at just jsoncpp-master your include would have to be #include <include/json/json.h> BUT any includes included by json.h would not know this and probably promptly fail because they'd be expecting the root of their tree to be json rather than include. The library expects you to point your tools at the include folder. Point anywhere else and you're gonna have a bad time. Commented Feb 4, 2023 at 1:54

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I was not able to make it work using whats in the github with different includes but after many trial and errors I finally did with vcpkg from the intructions here vcpkg.io/en/getting-started.html and those on the jsoncpp github about vcpkg. Ended up setting VCPKG_DEFAULT_TRIPLET to x64-windows. I also made a curl package with it. I dont know exactly what I ended up doing but it did work lol! I also dont know why every time I touch anything open source it ends up being a huge pain in the arse to make it work. Am I missing someting?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.