我正在尝试集成来自nlohmann的json c++库,同时简单地将'single_include‘文件复制到与我的main.cpp文件相同的目录。根据集成instructions
#include <nlohmann/json.hpp>
// for convenience
using json = nlohmann::json;
但是由于某些原因,编译器认为那里不存在这样的文件,我不知道我可以做些什么来使它工作。
我得到了完整的错误:
main.cpp:2:10: fatal error: json.hpp: No such file or directory
#include <json.hpp>
^~~~~~~~~~
compilation terminated.
(我猜由于json.hpp文件就在main.cpp文件的旁边,所以我不应该编写#include <nlohmann/json.hpp>
,尽管它在集成说明中是这样编写的,对吧?)
*这就是我目前在VS Code looks中的项目
发布于 2020-08-31 02:27:06
在C++中,当标头被尖括号(<>
)括起时,它会搜索包含路径中的标头,除非另外明确配置,否则包含路径通常不包括main.cpp
文件所在的目录。然而,当你的头被双引号括起来时,它会搜索当前目录,所以你应该包含"json.hpp"
而不是<json.hpp>
。
发布于 2021-03-16 14:17:50
对我来说,事实证明我还没有安装它,所以这解决了我的问题。
sudo apt install nlohmann-json-dev
https://stackoverflow.com/questions/63660646
复制相似问题