简体   繁体   中英

jsoncpp error: undefined reference to `Json::Value::Value(Json::ValueType)'

I'm making program to read and write json file. My code:

#include <bits/stdc++.h>
#include <json/json.h>
#include <json/reader.h>
using namespace std;

int main()
{
    ifstream file("input.json");
    Json::Value value;
    Json::Reader reader;

    reader.parse(file, value);

    cout << value << endl;
    return 0;
}

When I run the program, it's return errors:

C:\Users\Admin\AppData\Local\Temp\ccpsFhxG.o:filemanager.cpp:(.text+0x3f): undefined reference to `Json::Value::Value(Json::ValueType)'
C:\Users\Admin\AppData\Local\Temp\ccpsFhxG.o:filemanager.cpp:(.text+0x4b): undefined reference to `Json::Reader::Reader()'
C:\Users\Admin\AppData\Local\Temp\ccpsFhxG.o:filemanager.cpp:(.text+0x6b): undefined reference to `Json::Reader::parse(std::istream&, Json::Value&, bool)'
C:\Users\Admin\AppData\Local\Temp\ccpsFhxG.o:filemanager.cpp:(.text+0x7e): undefined reference to `Json::operator<<(std::ostream&, Json::Value const&)'   
C:\Users\Admin\AppData\Local\Temp\ccpsFhxG.o:filemanager.cpp:(.text+0xaa): undefined reference to `Json::Value::~Value()'
C:\Users\Admin\AppData\Local\Temp\ccpsFhxG.o:filemanager.cpp:(.text+0xdd): undefined reference to `Json::Value::~Value()'

I already try to add param -ljsoncpp but it said C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -ljsoncpp It's there any way to fix this problem? I installed jsoncpp from https://github.com/open-source-parsers/jsoncpp .

I fixed this problem. Just need to run file amalgamate.py (Python >= 2.6 required), it will create three files:

dist/jsoncpp.cpp, the source file to be added to your project
dist/json/json.h, the correspondent header file
dist/json/json-forwards.h, which contains forward declarations of JSON types.

Import file jsoncpp.cpp to your program and it works fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM