Get the App
SLTechnology News&Howtos  ›  Servers  › 

Muduo usage

Shulou Source: shulou.com Published: 2022-06-02 20:47:27 11月27日 Update

1. × × ×

The latest code on svn

1) tools to be installed

Yum install cmake

2) install boost

3) enter the home directory

. / build.sh

2 compilation exception

1) CMakeFiles/ttcp_blocking.dir/common.cc.o: In function `parseCommandLine (int, char**, Options*)':

/ root/workspace/muduo-master/examples/ace/ttcp/common.cc:14: undefined reference to

`boost::program_options::options_description::options_description (std::basic_string const&, unsigned int, unsigned int)'

From this error, we can know that it is caused by not specifying a link to the boost library.

2) add a link to boost in the CMakeLists.txt file

Set (CMAKE_CXX_FLAGS "- lboost_program_options")

Continue with the error message:

/ root/workspace/muduo-master/muduo/base/FileUtil.cc: In member function 'int

Muduo::FileUtil::ReadSmallFile::readToString (int, String*, int64_t*, int64_t*, int64_t*)':

/ root/workspace/muduo-master/muduo/base/FileUtil.cc:98: error: 'sizeof' cannot be used for incomplete classes

Type 'boost::STATIC_ASSERTION_FAILURE'

Since the problem has not been solved, try another way of thinking.

3) because the compiled files in the examples directory do not specify the boost library when they are linked, this leads to the first problem

Therefore, in the process of compilation, cancel the compilation of the examples content and choose to generate the version release

BUILD_NO_EXAMPLES=1 BUILD_TYPE=release. / build.sh-j2

For detailed parameter settings, please see build.sh.

3 compilation result

Generate a build folder at the level of the muduo directory

Library files: build/release/lib

Libmuduo_base.a libmuduo_http.a libmuduo_net.a

Libmuduo_base_cpp11.a libmuduo_inspect.a libmuduo_net_cpp11.a

4 simple test

Run bin/inspector_test and access it through the browser http://191.168.230.23:12345, please close linux

Firewall service iptbables stop.

Test results:

Name:inspector_test

State:S (sleeping)

Tgid:15762

Pid:15762

PPid:12064

TracerPid:0

Uid:0000

Gid:0000

5 individual tests

Muduo is a statically linked C++ library. When using the muduo library, you only need to set the header file path and library file path and link the corresponding static library file (- lmuduo_net-

Lmuduo_base) is fine.

Manually compile the first program that lost packets

Cd muduo-master/examples/simple/discard

Gmail + main.cc discard.cc-I / root/workspace/muduo-master/ / root/workspace/build/release/lib/libmuduo_base.a

/ root/workspace/build/release/lib/libmuduo_net.a-lpthread-o muduotest

Attach the Ubuntu compilation error here:

Compilation error, did not find the implementation of pthread_create, install libboost-dev to solve the problem

Use instructions:

Apt-get install gathers + cmake libboost-dev make git

Tags: Compile link file directory library file error problem test time program result path static build personal code information content parameter good header Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Docker Xiaomi Redmi Apple