CetOs6.5下 jsoncpp安装 NCURSES的安装

前端之家收集整理的这篇文章主要介绍了CetOs6.5下 jsoncpp安装 NCURSES的安装前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


NCURSES的安装

在安装MySQL时,有时提示缺少ncurses库,只需执行以下命令即可

yum install ncurses-devel


jsoncpp安装

1.安装环境:
Python(自带
scons (用来编译jsoncpp)
jsoncpp

2.从github下载最新版本jsoncpp
https://github.com/open-source-parsers/jsoncpp

3.安装scons
scons 官方网址http://www.scons.org/
找到Redhat版的rpm(比如scons-2.5.0-1.noarch.rpm),然后直接点击安装即可。

4.编译jsoncpp
进入到jsoncpp文件,然后在终端执行:
sudo scons platform=linux-gcc
这样就会在jsoncpp/libs/linux-gcc-x.x.x中找到两个库文件,一个静态库一个动态库。

5.编写测试程序:

<code class="hljs cpp has-numbering" style="padding: 0px; margin: 0px; display: block; color: inherit; Box-sizing: border-Box; font-family: 'Source Code Pro',monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-preprocessor" style="padding: 0px; margin: 0px; color: rgb(68,68,68); Box-sizing: border-Box;">#include "json/json.h"</span>
<span class="hljs-preprocessor" style="padding: 0px; margin: 0px; color: rgb(68,68); Box-sizing: border-Box;">#include <iostream></span>
<span class="hljs-keyword" style="padding: 0px; margin: 0px; color: rgb(0,136); Box-sizing: border-Box;">using</span> <span class="hljs-keyword" style="padding: 0px; margin: 0px; color: rgb(0,136); Box-sizing: border-Box;">namespace</span> <span class="hljs-built_in" style="padding: 0px; margin: 0px; color: rgb(102,102); Box-sizing: border-Box;">std</span>;
<span class="hljs-keyword" style="padding: 0px; margin: 0px; color: rgb(0,136); Box-sizing: border-Box;">int</span> main(){
  Json::Value  v;
   <span class="hljs-keyword" style="padding: 0px; margin: 0px; color: rgb(0,136); Box-sizing: border-Box;">return</span> <span class="hljs-number" style="padding: 0px; margin: 0px; color: rgb(0,102,102); Box-sizing: border-Box;">0</span>;
}</code>

其实只要第一句没问题就OK了。

6.以上程序用到了json.h,所以需要告诉编译器json.h的位置,只知道json.h的位置还不够,还需要库。 我的文件结构如下:

<code class="hljs avrasm has-numbering" style="padding: 0px; margin: 0px; display: block; color: inherit; Box-sizing: border-Box; font-family: 'Source Code Pro',monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">Lib所在目录:
   jsoncpp..
       libs..
           linux-gcc-<span class="hljs-number" style="padding: 0px; margin: 0px; color: rgb(0,102); Box-sizing: border-Box;">4.8</span><span class="hljs-number" style="padding: 0px; margin: 0px; color: rgb(0,102); Box-sizing: border-Box;">.2</span>..
                  libjson_linux-gcc-<span class="hljs-number" style="padding: 0px; margin: 0px; color: rgb(0,102); Box-sizing: border-Box;">.2</span>_libmt<span class="hljs-preprocessor" style="padding: 0px; margin: 0px; color: rgb(68,68); Box-sizing: border-Box;">.a</span>  libjson_linux-gcc-<span class="hljs-number" style="padding: 0px; margin: 0px; color: rgb(0,68); Box-sizing: border-Box;">.so</span> 
头文件所在目录:
  jsoncpp.. 
      include..
          json.. 
             json<span class="hljs-preprocessor" style="padding: 0px; margin: 0px; color: rgb(68,68); Box-sizing: border-Box;">.h</span></code>

这里在终端输入以下命令:

<code class="hljs lasso has-numbering" style="padding: 0px; margin: 0px; display: block; color: inherit; Box-sizing: border-Box; font-family: 'Source Code Pro',monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">export LD_LIBRARY_PATH<span class="hljs-subst" style="padding: 0px; margin: 0px; color: rgb(0,0); Box-sizing: border-Box;">=</span><span class="hljs-string" style="padding: 0px; margin: 0px; color: rgb(0,136,0); Box-sizing: border-Box;">'/Your Path/jsoncpp/libs/linux-gcc-4.8.2'</span>

g<span class="hljs-subst" style="padding: 0px; margin: 0px; color: rgb(0,0); Box-sizing: border-Box;">++</span> <span class="hljs-attribute" style="padding: 0px; margin: 0px; Box-sizing: border-Box;">-I</span> <span class="hljs-string" style="padding: 0px; margin: 0px; color: rgb(0,0); Box-sizing: border-Box;">'头文件所在目录'</span> <span class="hljs-attribute" style="padding: 0px; margin: 0px; Box-sizing: border-Box;">-L</span> <span class="hljs-string" style="padding: 0px; margin: 0px; color: rgb(0,0); Box-sizing: border-Box;">'lib所在目录'</span> <span class="hljs-attribute" style="padding: 0px; margin: 0px; Box-sizing: border-Box;">-ljson_linux</span><span class="hljs-attribute" style="padding: 0px; margin: 0px; Box-sizing: border-Box;">-gcc</span><span class="hljs-subst" style="padding: 0px; margin: 0px; color: rgb(0,0); Box-sizing: border-Box;">-</span><span class="hljs-number" style="padding: 0px; margin: 0px; color: rgb(0,102); Box-sizing: border-Box;">.2</span>_libmt test_json<span class="hljs-built_in" style="padding: 0px; margin: 0px; color: rgb(102,102); Box-sizing: border-Box;">.</span>cpp <span class="hljs-attribute" style="padding: 0px; margin: 0px; Box-sizing: border-Box;">-o</span> main

根据以上文件目录:
g<span class="hljs-subst" style="padding: 0px; margin: 0px; color: rgb(0,0); Box-sizing: border-Box;">'/Your Path/include'</span> <span class="hljs-attribute" style="padding: 0px; margin: 0px; Box-sizing: border-Box;">-L</span> <span class="hljs-string" style="padding: 0px; margin: 0px; color: rgb(0,0); Box-sizing: border-Box;">'/Your Path/jsoncpp/libs/linux-gcc-4.8.2'</span> <span class="hljs-attribute" style="padding: 0px; margin: 0px; Box-sizing: border-Box;">-ljson_linux</span><span class="hljs-attribute" style="padding: 0px; margin: 0px; Box-sizing: border-Box;">-gcc</span><span class="hljs-subst" style="padding: 0px; margin: 0px; color: rgb(0,102); Box-sizing: border-Box;">.</span>cpp <span class="hljs-attribute" style="padding: 0px; margin: 0px; Box-sizing: border-Box;">-o</span> main</code>

这里 -I 是指定头文件目录,-L 是指定lib目录,-ljson_linux-gcc-4.8.2_libmt 表示链接 lib目录下的libjson_linux-gcc-4.8.2_libmt.so 动态库。

export 每开一个终端就要输入一次,不然会出现error while loading shared libraries,这里暂时没去解决

关于error while loading shared libraries 可以参考以下链接: http://stackoverflow.com/questions/5357869/error-while-loading-shared-libraries

关于gcc命令不大明白可以参看以下链接: http://www.cnblogs.com/ggjucheng/archive/2011/12/14/2287738.html#_Toc311642848

关于安装jsoncpp,参考链接: http://blog.csdn.net/gogoytgo/article/details/46007689


文章来源:http://www.centoscn.com/image-text/install/2016/0505/7173.html

在安装前需要安装scons:

1.scons是神马?

scons是linux下的自动构建工具,类似cmake。

2. 安装

wget http://prdownloads.sourceforge.net/scons/scons-2.2.0.tar.gz .

tar zxvfscons-2.2.0.tar.gz

cdscons-2.2.0

python setup.py install

正常情况下,scons将安装到${PYTHON_INSTALL_DIR}/bin/下


走到这里已经安装OK了


3. hello world程序

三个文件hello.h hello.c main.c hello.h定义函数void hello(); hello.c中实现该函数,main.c中调用函数

编写SConstruct,scons构建时使用。内容如下:

Program('hello',['hello.c','main.c'])

开始构建

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gcc -o hello.o -c hello.c
gcc -o main.o -c main.c
gcc -o hello hello.o main.o
scons: done building targets.

此时二进制文件已经构建完成,scons贼好用。

4. 参考资料

更多配置:http://www.jb51.cc/article/p-dqpwtcdp-mg.html

相关代码下载:http://pan.baidu.com/share/link?shareid=239572&uk=908463093


http://www.cnblogs.com/xuqiang/archive/2013/01/23/2873729.html

原文链接:https://www.f2er.com/json/289362.html

猜你在找的Json相关文章