nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
42.92k stars 6.71k forks source link

"Integration" section of documentation needs update? #1505

Closed Memhir-Yasue closed 5 years ago

Memhir-Yasue commented 5 years ago

Hello, I declared the header file as #include <nlohmann/json.hpp> as the documentation suggested.

However, I ran into the following problem when complying

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

I found this issue from 2017 which suggests to instead use #include "nlohmann/json.hpp" https://github.com/melpon/wandbox/issues/209

No errors encountered afterwards when complying.

Using Ubuntu 18.04.02 with GCC 7.3.0

gregmarr commented 5 years ago

This means that you did not add the directory containing nlohmann in your compiler options as a system include directory. The <foo.h> syntax generally means "search in system include directories" while "foo.h" means "search in system include directories and the directory of the file doing the include".

nlohmann commented 5 years ago

@gregmarr is right. Furthermore, there are several package managers which all assume this way of including. As a working example, see the compiler call on the bottom of https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a8faa039ca82427ed29c486ffd00600c3.html#a8faa039ca82427ed29c486ffd00600c3

Memhir-Yasue commented 5 years ago

Gotcha! Thanks for the explanations! Learned something new!