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, 68); box-sizing: border-box;">#include <iostream></span>
<span class="hljs-keyword" style="padding: 0px; margin: 0px; color: rgb(0, 0, 136); box-sizing: border-box;">using</span> <span class="hljs-keyword" style="padding: 0px; margin: 0px; color: rgb(0, 0, 136); box-sizing: border-box;">namespace</span> <span class="hljs-built_in" style="padding: 0px; margin: 0px; color: rgb(102, 0, 102); box-sizing: border-box;">std</span>;
<span class="hljs-keyword" style="padding: 0px; margin: 0px; color: rgb(0, 0, 136); box-sizing: border-box;">int</span> main(){
Json::Value v;
<span class="hljs-keyword" style="padding: 0px; margin: 0px; color: rgb(0, 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, 102); box-sizing: border-box;">4.8</span><span class="hljs-number" style="padding: 0px; margin: 0px; color: rgb(0, 102, 102); box-sizing: border-box;">.2</span>..
libjson_linux-gcc-<span class="hljs-number" style="padding: 0px; margin: 0px; color: rgb(0, 102, 102); box-sizing: border-box;">4.8</span><span class="hljs-number" style="padding: 0px; margin: 0px; color: rgb(0, 102, 102); box-sizing: border-box;">.2</span>_libmt<span class="hljs-preprocessor" style="padding: 0px; margin: 0px; color: rgb(68, 68, 68); box-sizing: border-box;">.a</span> libjson_linux-gcc-<span class="hljs-number" style="padding: 0px; margin: 0px; color: rgb(0, 102, 102); box-sizing: border-box;">4.8</span><span class="hljs-number" style="padding: 0px; margin: 0px; color: rgb(0, 102, 102); box-sizing: border-box;">.2</span>_libmt<span class="hljs-preprocessor" style="padding: 0px; margin: 0px; color: rgb(68, 68, 68); box-sizing: border-box;">.so</span>
头文件所在目录:
jsoncpp..
include..
json..
json<span class="hljs-preprocessor" style="padding: 0px; margin: 0px; color: rgb(68, 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, 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, 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, 136, 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, 136, 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, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="padding: 0px; margin: 0px; color: rgb(0, 102, 102); box-sizing: border-box;">4.8</span><span class="hljs-number" style="padding: 0px; margin: 0px; color: rgb(0, 102, 102); box-sizing: border-box;">.2</span>_libmt test_json<span class="hljs-built_in" style="padding: 0px; margin: 0px; color: rgb(102, 0, 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, 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, 136, 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, 136, 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, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="padding: 0px; margin: 0px; color: rgb(0, 102, 102); box-sizing: border-box;">4.8</span><span class="hljs-number" style="padding: 0px; margin: 0px; color: rgb(0, 102, 102); box-sizing: border-box;">.2</span>_libmt test_json<span class="hljs-built_in" style="padding: 0px; margin: 0px; color: rgb(102, 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://*.com/questions/5357869/error-while-loading-shared-libraries
关于gcc命令不大明白可以参看以下链接: http://www.cnblogs.com/ggjucheng/archive/2011/12/14/2287738.html#_Toc311642848
关于安装jsoncpp,参考链接: http://blog.****.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 zxvf scons-2.2.0.tar.gz
cd scons-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://blog.****.net/andyelvis/article/details/7055377
相关代码下载:http://pan.baidu.com/share/link?shareid=239572&uk=908463093
http://www.cnblogs.com/xuqiang/archive/2013/01/23/2873729.html