Linux multi-threaded server-side programming learning muduo (a) Centos7 installation muduo network library

1, GitHub downloadsmuduo sourcehttps://github.com/chenshuo/muduo

Here Insert Picture Description
Here Insert Picture Description
I was taking root (root privileges landing operations need to be careful, not very familiar with, or ordinary user login, the next front landing plus operating authoritysudo), Download the documents folder in / root / Downloads file. It should be noted here, download theZIP fileTherefore you need to install unzip supportZIP tool, Where the reader can be resolved. I downloaded unzip in windows, then shared files to Linux.

2, install cmake

(1)安装cmake前需要的准备工作

Ensure that the system installed gcc, ncurses-devel

yum -y  install gcc-c++
yum -y  install ncurses-devel
(2)下载cmake软件包

Download https://cmake.org/files/v3.6/cmake-3.6.2.tar.gz I use the version 3.6.2, you canChoose Desired version.

Downloaded files in the / root / Downloads, opens a terminal at the folder, extracting files

# tar -zxvf  cmake-3.6.2.tar.gz  -C /usr/local   (PS:-C 后面指定解压到文件夹下  /usr/local)
# cd /usr/local/cmake-3.6.2
# ./configure    
(如果这一步提示需要其他的安装包,安装即可,或者自行百度怎么解决,我在这一步没遇到问题)
# make
# make install
(完成之后可以进行检查是否安装成功了)
/*  # cd bin 
    # ./cmake --version
 */   上面的两行命令为检查cmake是否安装成功了,如果安装成功,提示结构如图所示。

Here Insert Picture Description

(3) 接下来设置软连接,因为此时如果不进行软链接,每次运行cmake需要用
# /usr/local/cmake-3.6.2/bin/cmake --version (很麻烦)
 # ln -s /usr/local/cmake-3.6.2/bin/cmake /usr/bin/cmake
 (在任意目录进行检验是否设置成功,切换到家目录)
 # cd
 # cmake --version
 (如果运行成功表示设置成功)

3, install boost library

Here we must pay attention to the Linux system in the computerWhether boost related packages already existIf not pay attention to easily download a version to the back of the compiler you will be prompted to find muduo boost library.

(运行命令查看系统中已经有的boost相关的包)
# rpm -qa boost*

Here Insert Picture Description
My inside the computer version is 1.53.0
official website to download the Boost 1.53.0 (download version according to their own computers oh) https://sourceforge.net/projects/boost/files/boost/
Here Insert Picture Description

After downloading the installation finished

解压,方法如前,不再赘述。
安装之前,预先安装相关项。
# yum install gcc gcc-c++ bzip2 bzip2-devel bzip2-libs python-devel
# cd /root/Downloads
# sh ./bootstrap.sh  --prefix /usr/local/boost (在解压之后的文件夹下运行)
# ./b2  install
# cd ./tools/build 
#  ./bootstrap.sh
# ./b2  install  --prefix /usr/local/boost

4, the installation must rely on non-library

Here to see a lot of blog wrote the following installation methods, but incentos7Under the system, there is no corresponding software package, you need to make the appropriate changes.

# apt-get install libcurl4-openssl-dev libc-ares-dev 
# apt-get install protobuf-compiler libprotobuf-dev

This libcurl4-openssl-dev libc-ares-dev isUbuntuThe system is available, here we useCentos7 system. Therefore prompted to find the installation package.
Here Insert Picture Description
Here should be used

# yum install openssl
# yum install protobuf

5, compiled Muduo

If your previous steps are successful, then the next compile Muduo it!
Download and unzip the first step back off muduo folder

#  ./build.sh -j2

DuangRun error, OK, this time we work together to locate the error.
Here Insert Picture Description
Red underlined part probably meant to say in thisMutex.h header fileThe third line of the first column there is an error, then we open this folder, look in the end what is wrong. muduo-master / muduo / base / Mutex.h (PS: This is my muduo-master in git muduo download the compressed file after unpack folder name)
Here Insert Picture Description
to see the mistake?
Solution:This sentence written offOK, this sentence written off run

#  ./build.sh -j2

Here Insert Picture Description

Ha ha ha ha ha ha, resolved, finally Well, this network library, I spent an afternoon and a night time, last time success is really very happy ah! I recorded the process, you also want to install problems encountered in the process of muduo help!
Here Insert Picture Description

Well, one hundred percent.

Which generate executable code running tests to see if the installation was successful

# cd /home/(用户名)/Desktop/build/release-cpp11/bin
# ./inspector_test

Here Insert Picture Description
Open your browser and enter http://xxx.xxx.xxx.xxx:12345 whichxxx.xxx.xxx.xxxFor your own computer's IP. Can be used in LinuxView command ifconfig

Run results are shown in FIG.
Here Insert Picture Description

If you are wrong in the compilation process, we must remember to see build / release-cpp11 / CMakeFiles / CMakeError.log and CMakeOutput.log

How to use the network librarySee link using Muduo network library

Recommend a waySource Reading Tools, Understand, this software can not only display the relationship between function calls, you can always view the member variables and member functions of the class definition.
understand installation tutorial https://blog.csdn.net/YoungSusie/article/details/90905285

Guess you like

Origin blog.csdn.net/YoungSusie/article/details/90021742