cmake在Windows上找不到openssl

时间:2017-04-27 16:15:23

标签: c++ boost cmake openssl

我已经阅读过这篇文章但它没有回答我的问题:(cmake not able to find openssl

我在Windows 10 64位工作,我想在ssl支持下使用boost asio,所以我在C:\ Local \ OpenSSL-Win64中安装了openssl,我有一个环境变量指向这个。

我在cmake中有这段代码:

file(TO_CMAKE_PATH $ENV{OPENSSL_ROOT} OPENSSL_ROOT_DIR)
message(WARNING "root: ${OPENSSL_ROOT_DIR}")
find_package(OpenSSL )

message(WARNING "OpenSSL_VERSION: ${OPENSSL_VERSION}")
message(WARNING "OpenSSL_INCLUDE_DIR: ${OPENSSL_INCLUDE_DIR}")
message(WARNING "OpenSSL_LIBRARIES: ${OPENSSL_LIBRARIES}")

当我运行cmake时,我收到了这条消息:

CMake Warning at CMakeLists.txt:44 (message):
  root: C:/Local/OpenSSL-Win64


CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.1/Modules/FindOpenSSL.cmake:293 (list):
  list GET given empty list
Call Stack (most recent call first):
  CMakeLists.txt:45 (find_package)


CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.1/Modules/FindOpenSSL.cmake:294 (list):
  list GET given empty list
Call Stack (most recent call first):
  CMakeLists.txt:45 (find_package)


CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.1/Modules/FindOpenSSL.cmake:296 (list):
  list GET given empty list
Call Stack (most recent call first):
  CMakeLists.txt:45 (find_package)


CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.1/Modules/FindOpenSSL.cmake:298 (list):
  list GET given empty list
Call Stack (most recent call first):
  CMakeLists.txt:45 (find_package)


Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing:  OPENSSL_LIBRARIES) (found version ".0.0`")
CMake Warning at CMakeLists.txt:47 (message):
  OpenSSL_VERSION: .0.0`


CMake Warning at CMakeLists.txt:48 (message):
  OpenSSL_INCLUDE_DIR: C:/Local/OpenSSL-Win64/include


CMake Warning at CMakeLists.txt:49 (message):
  OpenSSL_LIBRARIES: SSL_EAY_LIBRARY-NOTFOUND;LIB_EAY_LIBRARY-NOTFOUND

可以看出cmake可以找到正确指向C的环境变量:/ Local / OpenSSL-Win64

有趣的是,它可以找到包含路径:

CMake Warning at CMakeLists.txt:48 (message):
OpenSSL_INCLUDE_DIR: C:/Local/OpenSSL-Win64/include

但版本和包含库不对。

有什么特定方法可以强迫cmake找到openssl吗?

如何确保找到合适的静态库?

编辑1

Aftre升级到cmake 3.8,现在,cmake可以找到openssl,但不能找到它的库。输出如下:

Found OpenSSL: C:/Local/OpenSSL-Win64/lib/libssl.lib (found version "1.1.0e") 
CMake Warning at CMakeLists.txt:52 (message):
  OpenSSL_VERSION: 1.1.0e


CMake Warning at CMakeLists.txt:53 (message):
  OpenSSL_INCLUDE_DIR: C:/Local/OpenSSL-Win64/include


CMake Warning at CMakeLists.txt:54 (message):
  OpenSSL_LIBRARIES:

为什么找不到图书馆?

编辑2

它无法找到库的原因是我使用了不同情况的变量名称。正确的名称是OPENSSL_LIBRARIES。

有关更多信息,请阅读findopenssl.cmake文件作为cmake发行版的一部分。

1 个答案:

答案 0 :(得分:3)

最新的OpenSSL版本(我认为1.1.x系列)略微改变了opensslv.h标题中指定版本号的格式。这导致CMake的FindOpenSSL.cmake模块中的版本解析代码失败,然后在CMake 3.5.0周围修复。此外,从OpenSSL 1.1.0开始,Windows上的库名称更接近它们的Unix对应物,并且名为libcrypto和libssl(可能带有更多后缀),而不是旧名称libeay32和ssleay32。 CMake 3.7.0包含此库名称更改的帐户更新。由于这两个更改和修复,如果要将OpenSSL 1.1.0或更高版本与CMake项目一起使用,则应该使用CMake 3.7.0或更高版本。