簡體   English   中英

jsoncpp 錯誤:未定義對 `Json::Value::Value(Json::ValueType)' 的引用

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

我正在編寫程序來讀寫 json 文件。 我的代碼:

#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;
}

當我運行程序時,它返回錯誤:

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()'

我已經嘗試添加參數-ljsoncpp但它說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有沒有辦法解決這個問題? 我從https://github.com/open-source-parsers/jsoncpp安裝了 jsoncpp。

我解決了這個問題。 只需要運行文件amalgamate.py (需要 Python >= 2.6),它將創建三個文件:

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.

將文件jsoncpp.cpp導入您的程序,它工作正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM