安装libsodium
加密库,如果需要使用ZMQ4的安全功能需要在安装ZMQ前安装它,并在ZMQ编译时添加–with-libsodium 也可以 --without-libsodium屏蔽该功能,通过不安装也能使用zmq。
下载地址
https://download.libsodium.org/libsodium/releases/
官网安装指导
https://doc.libsodium.org/installation/
实际操作
tar -xzvf libsodium-1.0.18.tar.gz ./configure --prefix=/usr/lib/libsodium make && make check sudo make install cp /usr/lib/libsodium/lib/pkgconfig/libsodium.pc /usr/lib/pkgconfig/
安装libzmq
git clone https://github.com/zeromq/libzmq.git cd ./libzmq ./autogen.sh ./configure --prefix=/usr/lib/zmq PKG_CONFIG_PATH=/usr/lib/pkgconfig --with-libsodium make sudo make install
没太具体看过编译选项,只是指定了下路径,有其他功能或者裁剪需求可自行查看help
cmake工程引用zmq
主CMakeLists.txt
# cmake version cmake_minimum_required(VERSION 3.10) project(zmq_pro) #Platform dependent if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux") message("this is Linux") SET(USR_LIB_DIR "/usr/lib/") add_definitions("-Wall -g") elseif(CMAKE_SYSTEM_NAME MATCHES "Windows") message("this is Windows") SET(USR_LIB_DIR "D://lib") add_definitions("-Wall ") endif() #find include and lib path find_path(inc_zmq NAMES zmq.h HINTS ${USR_LIB_DIR}/zmq/include) include_directories(${inc_log}) find_library(libzmq NAMES zmq HINTS ${USR_LIB_DIR}/zmq/lib) #set rpath SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) SET(CMAKE_INSTALL_RPATH ${libzmq}) set(LIB_ZMQ ${libzmq} CACHE INTERNAL "ZMQ Library location" ) set(INCLUDE_ZMQ ${inc_zmq} CACHE INTERNAL "ZMQ Include location" ) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS ON) set(CMAKE_C_STANDARD 17) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS ON) #Module #add_subdirectory(client) add_subdirectory(server)
子CMakeLists.txt
# cmake version cmake_minimum_required(VERSION 3.10) #add code file add_executable(zmq_server main.cc ll_zmq_server.cpp) target_link_directories(zmq_server PRIVATE ${INCLUDE_ZMQ}) target_link_libraries(zmq_server PRIVATE ${LIB_ZMQ}) install(TARGETS zmq_server RUNTIME DESTINATION bin)