Centos编译boost
1.下载最新的boost
http://www.boost.org/
2.解压文件
tar -xzvf boost_1_45_0.tar.gz
3.编译bjam
进入boost_1_45_0目录中,运行./bootstrap.sh,完成后会得到一个bjam
4.编译boost
./bjam --with-date_time --with-system --with-regex --with-thread --with-filesystem --with-serialization --with-iostreams --with-math --with-mpi --with-program_options --with-python --with-math --with-signals --layout=tagged install variant=debug,release link=static --runtime-link=static threading=multi stage
5.查看boost
编译完成后,在/usr/local/include/boost就有最新的boost头文件了,在/usr/local/lib就有编译好的.a库文件了。
虽然usr/local/include和/usr/include都有目录,但GCC是先访问/usr/local/include,所以编译完成后,就可以默认使用boost了。
6.测试boost
vi testboost.cpp
#include <iostream>
#include <boost/version.hpp>
int main()
{
std::cout<<BOOST_VERSION<<std::endl;
return 0;
}
编译:g++ -o testboost testboost.cpp
/*linux - centos下boost库的安装
- yum install boost
- yum install boost-devel
- yum install boost-doc
*/
libmemcached安装及简单例子
1、下载安装libmemcached
$ wget http://launchpad.net/libmemcached/1.0/0.44/+download/libmemcached-0.44.tar.gz
$ tar xvzf libmemcached-0.44tar.gz
$ cd libmemcached-0.44
$ ./configure
$ make
$ sudo make install
libmemcached 默认安装在/usr/local/,头文件安装在/usr/local/include/libmemcachde/,动态库默认安装在/usr/local/lib/下。
2、libmemcached简单测试使用
1 #include <iostream>
2 #include <string>
3 #include <libmemcached/memcached.h>
4
5 using namespace std;
6
7 int main(int argc,char *argv[])
8 {
9 //connect server
10 memcached_st *memc;
11 memcached_return rc;
12 memcached_server_st *server;
13 time_t expiration;
14 uint32_t flags;
15
16 memc = memcached_create(NULL);
17 server = memcached_server_list_append(NULL,"localhost",11211,&rc);
18 rc=memcached_server_push(memc,server);
19 memcached_server_list_free(server);
20
21 string key = "key";
22 string value = "value";
23 size_t value_length = value.length();
24 size_t key_length = key.length();
25
26
27 //Save data
28 rc=memcached_set(memc,key.c_str(),key.length(),value.c_str(),value.length(),expiration,flags);
29 if(rc==MEMCACHED_SUCCESS)
30 {
31 cout<<"Save data:"<<value<<" sucessful!"<<endl;
32 }
33
34 //Get data
35 char* result = memcached_get(memc,key.c_str(),key_length,&value_length,&flags,&rc);
36 if(rc == MEMCACHED_SUCCESS)
37 {
38 cout<<"Get value:"<<result<<" sucessful!"<<endl;
39 }
40
41 //Delete data
42 rc=memcached_delete(memc,key.c_str(),key_length,expiration);
43 if(rc==MEMCACHED_SUCCESS)
44 {
45 cout<<"Delete key:"<<key<<" sucessful!"<<endl;
46 }
47
48 //free
49 memcached_free(memc);
50 return 0;
51 }
52
53
编译:g++ -o testmemcached testmemcached.cpp -lmemcached
运行:./testmemcached
结果:Save data:value sucessful!
Get value:value sucessful!
Delete key:key sucessful!
QT的安装
是解压缩剪切过去的。
下面是全局环境配置:
export PATH=/usr/lib:/usr/local/lib:$PATH
export LD_LIBRARY_PATH=/usr/lib64/plugins:/usr/lib64/plugins/sqldrivers:$LD_LIBRARY_PATH
export QT_PLUGIN_PATH=/usr/lib64/plugins
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
export PATH=/usr/lib:/usr/local/lib:$PATH
export LD_LIBRARY_PATH=/usr/lib64/plugins:/usr/lib64/plugins/sqldrivers:/usr/lib64/sqldrivers:$LD_LIBRARY_PATH
export QT_PLUGIN_PATH=/usr/lib64/plugins
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
protobuf的安装
protobuf-2.5.0.tar.gz上传到百度云盘供大家下载,地址: http://pan.baidu.com/s/1pJlZubT
1、protobuf是google公司提出的数据存储格式,详细介绍可以参考:https://code.google.com/p/protobuf/
2、下载最新的protobuf,下载地址:https://code.google.com/p/protobuf/downloads/list
3、下载protobuf2.5.o版本,protobuf-2.5.0.tar.gz解压并进行安装。
解压:tar xvf protobuf-2.5.0.tar.gz
安装步骤:(1)./configure (2)make (3)make check (4)make install
注意:安装成功后,将它的bin和lib目录分别加入到PATH和LD_LIBRARY_PATH环境变量,以方便直接调用。
通常建议安装到/usr/local目录下,执行configure时,指定--prefix=/usr/local/protobuf即可
设置环境变量过程:编辑/etc/profile,在文件末尾添加:
export PATH=$PATH:/usr/local/protobuf/bin export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/protobuf/lib
最后输入 protoc --version命令,如显示libprotoc 2.5.0则安装成功