CentOS下Jsoncpp安裝配置的方法
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.
到此這篇關(guān)于CentOS下Jsoncpp安裝配置的方法的文章就介紹到這了,更多相關(guān)Jsoncpp安裝配置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
如何利用C語言位運算解決只出現(xiàn)一次的數(shù)字
這篇文章主要給大家介紹了關(guān)于如何利用C語言位運算解決只出現(xiàn)一次的數(shù)字的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-04-04

