CentOS下Jsoncpp安装配置

1. 安装

执行命令

[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. 测试

创建测试文件夹和两个文件

[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

执行可执行文件看到如下,安装成功

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

执行可执行文件看到如下,安装成功

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


**解决办法**

执行一下 ldconfig 就行了

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

若出现如下提示可直接忽略,不是错误。

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.

.
.
.
.
.
.


桃花仙人种桃树,又摘桃花换酒钱_

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值