centos下muduo库的安装与使用

一、下载muduo库

git地址:

https://github.com/chenshuo/muduo

二、安装cmake

确保系统安装gcc,ncurses-devel(注意gcc的版本要支持c++11,centos的默认版本不支持)

yum -y install gcc-c++

yum -y install ncurses-devel

(注意,使用centos的安装命令是yum)

cmake地址:

 https://cmake.org/files/v3.6/cmake-3.6.2.tar.gz 

三、安装boost库

地址:

 https://sourceforge.net/projects/boost/files/boost/

四、安装非必要的依赖库

# apt-get install libcurl4-openssl-dev libc-ares-dev

# apt-get install protobuf-compiler libprotobuf-dev

此处看到不少博客写的下面的安装方法,可是在centos系统下,根本没有对应的软件包,需要进行相应的修改,如下:

# yum install openssl

# yum install protobuf

五、编译muduo

# ./build.sh -j2

六、在自己的项目中使用muduo库

muduo是静态链接的c++程序库,使用muduo库的时候,需要设置好头文件路径(例如../build/release-install/include)和库文件路径(例如../build/release-install/lib)并在编译时链接相应的静态库文件(-lmuduo_net -lmuduo_base)即可。 
相应的示例Makefile地址:https://github.com/chenshuo/muduo-tutorial

在自己项目中编译的方法:

g++ main.cc   -I /(头文件路径)/muduo/   /(库文件路径)/build/release-cpp11/lib/libmuduo_base.a /(库文件路径)/build/release-cpp11/lib/libmuduo_net.a  -lpthread -o test -std=c++11

注意:一定要加上-std=c++11,否则报错:

error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值