Linux multi-threaded server-side programming learning muduo (four) finger implementation of the service

Example seven-step realization finger Service


In this paper, the teacher Chen Shuo Linux multi-threaded server-side programmingAs a reference book, shows how to write the corresponding CMakeLists.txt by teacher Chen Shuo source code, then compile and run. (Before the experiment is performed in this section, needInstall network libraryReference links https://blog.csdn.net/YoungSusie/article/details/90021742 andSet of libraries and header filesReference links https://blog.csdn.net/YoungSusie/article/details/90035042 )
Chen Shuo teacher in the source code, under example / twisted / finger contains 01-07 code file, a file and a README file CMakeLists.txt
Here Insert Picture Description
among them, the contents of the file CMakeLists.txt
Here Insert Picture Description
obviously, this is not a complete cmakelists file, therefore, the firstModify the content of CMakeLists.txt

  • Establish CMakeLists.txt file

cmake_minimum_required(VERSION 2.6)

project(figure C CXX)

enable_testing()

if(NOT MUDUO_PATH)  
    set(MUDUO_PATH "/usr")
endif()

set(CXX_FLAGS
 -g
 # -DVALGRIND
 -DCHECK_PTHREAD_RETURN_VALUE
 -D_FILE_OFFSET_BITS=64
 -Wall
 -Wextra
 -Werror
 -Wconversion
 -Wno-unused-parameter
 -Wold-style-cast
 -Woverloaded-virtual
 -Wpointer-arith
 -Wshadow
 -Wwrite-strings
 -march=native
 # -MMD
 #-std=c++11
 -std=c++0x
 -rdynamic
 )

if(CMAKE_BUILD_BITS EQUAL 32)
  list(APPEND CXX_FLAGS "-m32")
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  list(APPEND CXX_FLAGS "-Wno-null-dereference")
  list(APPEND CXX_FLAGS "-Wno-sign-conversion")
  list(APPEND CXX_FLAGS "-Wno-unused-local-typedef")
  list(APPEND CXX_FLAGS "-Wthread-safety")
  list(REMOVE_ITEM CXX_FLAGS "-rdynamic")
endif()
string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CXX_FLAGS}")

set(CMAKE_CXX_FLAGS_DEBUG "-O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)


find_path(Muduo_INCLUDE_DIR muduo "${MUDUO_PATH}/include")
find_path(Muduo_LIBRARY_DIR libmuduo_net.a "${MUDUO_PATH}/lib")
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${Muduo_LIBRARY_DIR})
message(STATUS ${Muduo_INCLUDE_DIR})
message(STATUS ${Muduo_LIBRARY_DIR})

include_directories(${Muduo_INCLUDE_DIR})
find_library(muduo_base muduo_base)
find_library(muduo_net muduo_net)
message(STATUS ${muduo_base})
message(STATUS ${muduo_net})

find_package(Boost REQUIRED)
find_package(ZLIB)
find_path(CARES_INCLUDE_DIR ares.h)
find_library(CARES_LIBRARY NAMES cares)
find_path(MHD_INCLUDE_DIR microhttpd.h)
find_library(MHD_LIBRARY NAMES microhttpd)
find_library(BOOSTTEST_LIBRARY NAMES boost_unit_test_framework)
find_library(BOOSTPO_LIBRARY NAMES boost_program_options)
find_library(BOOSTSYSTEM_LIBRARY NAMES boost_system)
find_path(TCMALLOC_INCLUDE_DIR gperftools/heap-profiler.h)
find_library(TCMALLOC_LIBRARY NAMES tcmalloc_and_profiler)
find_path(HIREDIS_INCLUDE_DIR hiredis/hiredis.h)
find_library(HIREDIS_LIBRARY NAMES hiredis)
find_path(GD_INCLUDE_DIR gd.h)
find_library(GD_LIBRARY NAMES gd)
find_program(THRIFT_COMPILER thrift)
find_path(THRIFT_INCLUDE_DIR thrift)
find_library(THRIFT_LIBRARY NAMES thrift)  


include_directories(${Boost_INCLUDE_DIRS})
include_directories(${PROJECT_SOURCE_DIR})


add_executable(twisted_finger01 finger01.cc)
target_link_libraries(twisted_finger01 ${muduo_net})
target_link_libraries(twisted_finger01 ${muduo_base})   
target_link_libraries(twisted_finger01 pthread rt)

add_executable(twisted_finger02 finger02.cc)
target_link_libraries(twisted_finger02 ${muduo_net})
target_link_libraries(twisted_finger02 ${muduo_base}) 
target_link_libraries(twisted_finger02 pthread rt)

add_executable(twisted_finger03 finger03.cc)
target_link_libraries(twisted_finger03 ${muduo_net})
target_link_libraries(twisted_finger03 ${muduo_base}) 
target_link_libraries(twisted_finger03 pthread rt)

add_executable(twisted_finger04 finger04.cc)
target_link_libraries(twisted_finger04 ${muduo_net})
target_link_libraries(twisted_finger04 ${muduo_base}) 
target_link_libraries(twisted_finger04 pthread rt)

add_executable(twisted_finger05 finger05.cc)
target_link_libraries(twisted_finger05 ${muduo_net})
target_link_libraries(twisted_finger05 ${muduo_base}) 
target_link_libraries(twisted_finger05 pthread rt)

add_executable(twisted_finger06 finger06.cc)
target_link_libraries(twisted_finger06 ${muduo_net})
target_link_libraries(twisted_finger06 ${muduo_base}) 
target_link_libraries(twisted_finger06 pthread rt)

add_executable(twisted_finger07 finger07.cc)
target_link_libraries(twisted_finger07 ${muduo_net})
target_link_libraries(twisted_finger07 ${muduo_base}) 
target_link_libraries(twisted_finger07 pthread rt)
  • include partial modification of the source code

The finger 01-07 code include "" all to include <>
Here Insert Picture Description
all changes are complete, the terminal opens a folder in the finger

#  mkdir build

#  cd  build

# cmake ..

#  make

Here Insert Picture Description

  • test

Open a terminal in / build / bin directory, run finger07

#  ./twisted_finger07

Open another terminal run command

# telnet localhost 1079

Here Insert Picture Description

Guess you like

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