CMake 链接 OpenSSL 静态库
2022-08-23 22:24:21 3054
示例CMakeLists.txt如下
cmake_minimum_required(VERSION 3.5)
project(test CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function")
set(SYSTEM_LIBS stdc++ pthread)
# 静态编译
set(CMAKE_EXE_LINKER_FLAGS "-static")
add_executable(${PROJECT_NAME} main.cc)
find_library(SSL_LIB libssl.a REQUIRED)
find_library(CRYPTO_LIB libcrypto.a REQUIRED)
target_link_libraries(${PROJECT_NAME}
${SSL_LIB}
${CRYPTO_LIB}
${CMAKE_DL_LIBS}
${SYSTEM_LIBS})
若链接的其他静态库也链接了OpenSSL, 则要注意链接顺序