'Getting "json.hpp: No such file or directory" error despite having json.hpp in the same folder as main.cpp

I'm trying to integrate the json c++ library from nlohmann, while simply copying the 'single_include' file to the same directory as my main.cpp file. As per the integration instructions


#include <nlohmann/json.hpp>

// for convenience
using json = nlohmann::json;

But for some reason the compiler thinks that no such file exists there, and I have no idea what I could possibly do differently to make this work.

Full error I'm getting:

main.cpp:2:10: fatal error: json.hpp: No such file or directory
 #include <json.hpp>
          ^~~~~~~~~~
compilation terminated.

(I'm guessing that since the json.hpp file is right next to the main.cpp file, I shouldn't write #include <nlohmann/json.hpp> despite it's being written like that in the integration instructions, right?)

*This is how my project in VS Code looks at the moment



Solution 1:[1]

In C++, when headers are surrounded by angle brackets (<>), it searches for the headers in the include paths, which usually do not include the directory that your main.cpp file is located unless explicitly configured otherwise. However, when your headers are surrounded by double quotes, it searches the current directory, so you should include "json.hpp" instead of <json.hpp>.

Solution 2:[2]

For me, it turned out I havn't installed that yet so this solved my problem.

sudo apt install nlohmann-json-dev

Solution 3:[3]

sudo cd /usr/include/ && wget https://github.com/nlohmann/json/releases/download/v3.10.5/json.hpp

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aplet123
Solution 2 Tranks Naing
Solution 3 M22