CMake没有链接OpenSSL

时间:2018-01-30 15:17:45

标签: c cmake

我目前正在制作一个将使用OpenSSL的静态库。当CMake生成MakeFiles时,OpenSSL库没有链接在其中,因此编译失败并出现错误:

iot.c:(.text+0x3f5): undefined reference to `EVP_sha256'
iot.c:(.text+0x41c): undefined reference to `HMAC'

我首先想到的可能是CMake指令应该放在应该放在iotlib / CMakeLists.txt中的CMakeLists.txt中,但是在生成MakeFiles时我会遇到错误。

主文件只是使用iotlib和测试,而库的所有代码都在iotlib文件中。

我的CMakeLists.txt的代码

cmake_minimum_required(VERSION 3.5)
project(iotcloud_lib)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")

enable_testing()

# Includes for checkers
include(cppcheck.cmake) # TODO: Move to a module

set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})

# Set compiler flags
set (warnings "-Wall -Wextra -Werror")

include_directories("${PROJECT_SOURCE_DIR}")
add_subdirectory(iotlib)
add_subdirectory(tests)

add_executable(iotcloud ${PROJECT_SOURCE_DIR}/main.c)

find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
target_link_libraries(iotcloud ${OPENSSL_LIBRARIES})
target_link_libraries(iotcloud iotlib)

我的iotlib / CMakeLists.txt中的行

add_library (iotlib STATIC iot.c)

这就是我决定使用我的文件夹结构的方式。

+-- bin
+-- build
|   +-- MakeFile
|   +-- iotlib
|       +-- MakeFile
+-- CMakeLists.txt
+-- CMakeModules
|   +-- FindCheck.cmake
|   +-- FindOpenSSL.cmake
|   +-- FindPackageHandleStandardArgs.cmake
|   +-- FindPackageMessage.cmake
+-- cppcheck.cmake
+-- iotlib
|   +-- algo.h
|   +-- CMakeLists.txt
|   +-- iot.c
|   +-- iot_error.h
|   +-- iot.h
+-- main.c
+-- tests

0 个答案:

没有答案