简体   繁体   English

cmake在Windows上找不到OpenSSL

[英]cmake can not find openssl on windows

I already read this post and it did not answer my questions: ( cmake not able to find openssl ) 我已经阅读了这篇文章,但没有回答我的问题:( cmake无法找到openssl

I am working in windows 10 64 bit and I want to use boost asio with ssl support, so I installed openssl in C:\\Local\\OpenSSL-Win64 and I have a environment variable pointing to this. 我正在Windows 10 64位环境中工作,并且我想使用带有ssl支持的boost asio,所以我在C:\\ Local \\ OpenSSL-Win64中安装了openssl,并且有一个指向此的环境变量。

I have this code in cmake: 我在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}")

and when I run the cmake, I am getting this message: 当我运行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

as it can be seen the cmake could find the environment variable which is correctly pointed to C:/Local/OpenSSL-Win64 可以看出,cmake可以找到正确指向C:/ Local / OpenSSL-Win64的环境变量

also interestingly, it can find the include path: 同样有趣的是,它可以找到包含路径:

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

but the version, and include library is not right. 但是版本和包含库不正确。

is there any specific ways that I can force cmake to find the openssl? 有什么可以强制cmake查找openssl的特定方法吗?

How can I make sure that it finds the suitable static library? 我如何确保它找到合适的静态库?

Edit 1 编辑1

Aftre upgrading to cmake 3.8, now, cmake can find openssl, but not its libraries. Aftre升级到cmake 3.8,现在,cmake可以找到openssl,但找不到其库。 The output is as follow: 输出如下:

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:

Why libraries are not found? 为什么找不到库?

Edit 2 编辑2

The reason that it could not find library was that I used the variable name with a different case. 它找不到库的原因是我将变量名使用了不同的大小写。 The correct name is OPENSSL_LIBRARIES. 正确的名称是OPENSSL_LIBRARIES。

For more information read the findopenssl.cmake file as part of the cmake distribution. 有关更多信息,请阅读cmake发行版中的findopenssl.cmake文件。

More recent OpenSSL versions (the 1.1.x series I think) slightly changed the formatting of how the version number was specified in the opensslv.h header. 最新的OpenSSL版本(我认为是1.1.x系列)稍微改变了在opensslv.h标头中指定版本号的格式。 This caused CMake's version parsing code in its FindOpenSSL.cmake module to fail, which was then fixed around CMake 3.5.0. 这导致CMake的FindOpenSSL.cmake模块中的版本分析代码失败,然后围绕CMake 3.5.0进行了修复。 Furthermore, from OpenSSL 1.1.0, the library names on Windows are closer to their Unix counterparts and are named libcrypto and libssl (possibly with further suffixes) instead of the old names libeay32 and ssleay32. 此外,从OpenSSL 1.1.0开始,Windows上的库名称更接近于Unix上的库名称,并分别命名为libcrypto和libssl(可能带有更多后缀),而不是旧名称libeay32和ssleay32。 CMake 3.7.0 contained the update to account for this library name change. CMake 3.7.0包含此库名称更改的更新。 As a result of these two changes and fixes, if you want to use OpenSSL 1.1.0 or later with a CMake project, you should probably be using CMake 3.7.0 or later. 由于这两个更改和修复,如果要对CMake项目使用OpenSSL 1.1.0或更高版本,则可能应该使用CMake 3.7.0或更高版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM