【发布时间】:2016-08-19 09:33:07
【问题描述】:
当我运行以下代码时:
#include <cstdio>
#include <iostream>
#include <fstream>
#include <cstring>
#include <C:\Users\User\Documents\jsoncpp-master\dist\json\json.h>
#include <C:\Users\User\Documents\jsoncpp-master\dist\json\json-forwards.h>
using namespace std;
int main(){
Json::Value root;
Json::Reader reader;
ifstream file("test.json");
return 0;
}
我收到以下错误:
undefined reference to `Json::Reader::Reader()'
undefined reference to `Json::Value::Value(Json::ValueType)'
我正在尝试编写一个程序来读取 JSON 文件,并且此代码还必须输出 JSON 文件中的数据以供另一个 C++ 模块使用。
更新
#include <cstdio>
#include <iostream>
#include <fstream>
#include <cstring>
#include "dist\jsoncpp.cpp"
using namespace std;
int main(){
Json::Value root;
Json::Reader reader;
ifstream file("test.json");
return 0;
}
我已更改代码以删除完整链接并插入我运行后得到的 dist 文件夹:
python amalgamate.py
我将头文件输入到 C:\MinGW\include
我现在在 jsoncpp.cpp 文件中遇到很多错误(这是我运行 python 命令后得到的文件,我根本没有更改它)。所有的错误 说出同样的信息,即:
first defined here
【问题讨论】:
-
Json类在哪里定义? -
链接器错误。您必须与 jsoncpp 库链接。
-
[OT]:不要使用包含的完整路径。为您的构建系统指定其他目录以查找标头。
-
你是如何构建你的项目的?你是如何链接 JsonCpp 的?你有关于如何使用 JsonCpp 的 RTFM 吗? (好像没有)