Reputation: 109
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
json.hpp is the single required file in single_include/nlohmann or released here. You need to add
#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
Upvotes: 4
Views: 19743
Reputation: 171
For me, I had to use this package instead:
sudo apt install nlohmann-json3-dev
Upvotes: 5
Reputation: 595
sudo cd /usr/include/ && wget https://github.com/nlohmann/json/releases/download/v3.10.5/json.hpp
Upvotes: 2
Reputation: 95
For me, it turned out I havn't installed that yet so this solved my problem.
sudo apt install nlohmann-json-dev
Upvotes: 5
Reputation: 35560
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>
.
Upvotes: 8