一、下载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.