Closed TomyFrank closed 2 months ago
You need to properly configure the library search path to the json/include
folder and then use #include <nlohmann/json.hpp>
.
You have said it's a header-only library. so inclduing that would be enough useually but it's not. How to properly configure the library search path to the json/include?
You did not use the single header version which is in the single_include
folder. Otherwise, follow https://github.com/nlohmann/json?tab=readme-ov-file#integration.
The single_include
folder doesn't exist in the repo folder so I downloaded both json
and json_fwd
headers in the project directory and changed the code:
#include <iostream>
#include "json.hpp"
#include "json_fwd.hpp"
int main() {
auto j = R"(
{
"happy": true,
"pi": 3.141
}
)"_json;
auto data = j.dump();
std::cout << data << '\n';
return 0;
}
Error:
json.hpp:34:10: fatal error: nlohmann/adl_serializer.hpp: No such file or directory
34 | #include <nlohmann/adl_serializer.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
single_include
folder. Please check.include
folder, then just including json.hpp
or json_fwd.hpp
(don't include both, you probably only need json.hpp
), then you must set your include path.Downloaded the ZIP and inslcued json.hpp
and it runs. Thanks.
So the easiest way to use nlohmann-json is this way yeah?
Good that you managed it.
Description
I've cloned the repo and tried to use it in a simple C++ app but it produces an error.
Reproduction steps
After cloning the repo, moved the
json
folder in my project directory then includedjson.hpp
it got the error:Expected vs. actual results
I expected the string
{"happy": true,"pi": 3.141}
on TerminalMinimal code example
Error messages
Compiler and operating system
Linux GCC
Library version
version 3
Validation
develop
branch is used.