当我运行以下代码时:
#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++ 模块使用。
UPDATE
#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
仅将 h 文件包含到源代码中是不够的。
您需要在项目中编译jsoncpp.cpp。
请关注https://github.com/open-source-parsers/jsoncpp#generating-amalgamated-source-and-header https://github.com/open-source-parsers/jsoncpp#generating-amalgamated-source-and-header并将 jsoncpp.cpp、json/json.h、json/forwards.h 添加到您的项目中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)