I am trying to use the Nlohmann JSON parser in a C++17 program to parse GeoJSON files. The GitHub documentation says to add the header file json.hpp
using these code lines:
#include <nlohmann/json.hpp>
using json = nlohmann::json;
I am building this in Ubuntu 22.04 just using this simple g++ compiler command:
g++ geojson geojson.cpp -std=c++17 ./geojson
But I get the following error:
geojson.cpp:3:10: fatal error: nlohmann/json.hpp: No such file or directory
3 | #include <nlohmann/json.hpp>
I have tried downloading json.hpp
from the repo and putting it in the include directory and then use
#include "include/json.hpp"
But that just kicks the can down the road as json.hpp
has many includes from <nlohmann>
.
I've tried vcpkg but that produces other errors.
I would really prefer to get it working with g++ as this is a very simple program, and according to their own GitHub this method should work fine.
What I am doing wrong?
I am trying to use the Nlohmann JSON parser in a C++17 program to parse GeoJSON files. The GitHub documentation says to add the header file json.hpp
using these code lines:
#include <nlohmann/json.hpp>
using json = nlohmann::json;
I am building this in Ubuntu 22.04 just using this simple g++ compiler command:
g++ geojson geojson.cpp -std=c++17 ./geojson
But I get the following error:
geojson.cpp:3:10: fatal error: nlohmann/json.hpp: No such file or directory
3 | #include <nlohmann/json.hpp>
I have tried downloading json.hpp
from the repo and putting it in the include directory and then use
#include "include/json.hpp"
But that just kicks the can down the road as json.hpp
has many includes from <nlohmann>
.
I've tried vcpkg but that produces other errors.
I would really prefer to get it working with g++ as this is a very simple program, and according to their own GitHub this method should work fine.
What I am doing wrong?
Share Improve this question edited Mar 24 at 4:00 Remy Lebeau 601k36 gold badges507 silver badges851 bronze badges asked Mar 23 at 18:39 Ed FriesemaEd Friesema 214 bronze badges 3 |1 Answer
Reset to default 2For a single-file include package you're supposed to have the single-include header from the
single_include/nlohmann
directory from the repository, not the one from theinclude
!your include path must include a folder that contains a folder called
nlohmann
that in turn contains thatjson.hpp
from the said location.
At its simplest, something like this should work:
project/
geojson.cpp
nlohmann/
json.hpp
Finally the compilation command surely ought to be something like
g++ -std=c++17 geojson.cpp -o geojson -Wall -Wextra
what you provided in your question would not even work.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744273246a4566204.html
nlohmann
directory is.-I <the directory above nlohmann>
– Ted Lyngmo Commented Mar 23 at 18:46single_include/nlohmann/json.hpp
header – Ted Lyngmo Commented Mar 23 at 18:48g++ geojson geojson.cpp -std=c++17 ./geojson
looks wrong. Ifgeojson
is the output, you should specify it with-o geojson
, once. – Ted Lyngmo Commented Mar 23 at 18:50