溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

CentOS下怎么安裝配置Jsoncpp

發(fā)布時間:2022-02-24 13:55:01 來源:億速云 閱讀:323 作者:iii 欄目:開發(fā)技術(shù)

今天小編給大家分享一下CentOS下怎么安裝配置Jsoncpp的相關(guān)知識點,內(nèi)容詳細,邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。

1. 安裝

執(zhí)行命令

[root@VM-0-9-centos ~]# cd /home
[root@VM-0-9-centos home]# mkdir jsoncpp
[root@VM-0-9-centos home]# cd jsoncpp/
[root@VM-0-9-centos jsoncpp]# wget https://github.com/open-source-parsers/jsoncpp/archive/1.9.4.zip
[root@VM-0-9-centos jsoncpp]# unzip 1.9.4.zip
[root@VM-0-9-centos jsoncpp]# cd jsoncpp-1.9.4/
[root@VM-0-9-centos jsoncpp-1.9.4]# cmake .
[root@VM-0-9-centos jsoncpp-1.9.4]# make
[root@VM-0-9-centos jsoncpp-1.9.4]# make install

2. 測試

創(chuàng)建測試文件夾和兩個文件

[root@VM-0-9-centos jsoncpp-1.9.4]# mkdir xltest
[root@VM-0-9-centos jsoncpp-1.9.4]# cd xltest
[root@VM-0-9-centos xltest]# vim jsontest.json
[root@VM-0-9-centos xltest]# vim jsontest.cpp

其中jsontest.json 如下

[{"name":"Long", "age":6}]

jsontest.cpp 如下

#include <fstream>
#include <iostream>
#include <json/json.h>
#include <cassert>
#include <errno.h>
#include <string.h>
using namespace std;
int main(void)
{
    ifstream ifs;
    ifs.open("jsontest.json");
    assert(ifs.is_open());
    Json::Reader reader;
    Json::Value root;
    if (!reader.parse(ifs, root, false))
    {
        cout << "reader parse error: " << strerror(errno) << endl;
        return -1;
    }
    string name;
    int age;
    int size;
    size = root.size();
    cout << "total " << size << " elements" << endl;
    for (int i = 0; i < size; ++i)
    {
        name = root[i]["name"].asString();
        age = root[i]["age"].asInt();
        cout << "name: " << name << ", age: " << age << endl;
    }
    return 0;
}

編譯

[root@VM-0-9-centos xltest]# g++ jsontest2.cpp

執(zhí)行可執(zhí)行文件看到如下,安裝成功

[root@VM-0-9-centos xltest]# ./a.out
total 1 elements
name: long, age: 6.

執(zhí)行可執(zhí)行文件看到如下,安裝成功

3. 問題及解決

問題如下,

[root@VM-0-9-centos xltest]# ./a.out
/a.out: error while loading shared libraries: libjsoncpp.so.24: cannot open shared object file: No such file or directory

**解決辦法**

執(zhí)行一下 ldconfig 就行了

[root@VM-0-9-centos xltest]# ldconfig

若出現(xiàn)如下提示可直接忽略,不是錯誤。

ldconfig: /usr/local/lib64/libstdc++.so.6.0.28-gdb.py is not an ELF file - it has the wrong magic bytes at the start.

以上就是“CentOS下怎么安裝配置Jsoncpp”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學(xué)習(xí)更多的知識,請關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI