CMake无法找到OpenSSL库


117

我正在尝试安装一个软件,当我在Commandlin cmake上
给出命令时,它会使用cmake自行安装。需要OpenSSL):-

 cmake ..
-- Could NOT find Git (missing:  GIT_EXECUTABLE) 
ZLib include dirs: /usr/include
ZLib libraries: /usr/lib/arm-linux-gnueabihf/libz.so
Compiling with SSL support
CMake Error at /usr/local/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (message):
  Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
  system variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES
  OPENSSL_INCLUDE_DIR)
Call Stack (most recent call first):
  /usr/local/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:291 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/share/cmake-2.8/Modules/FindOpenSSL.cmake:313 (find_package_handle_standard_args)
  CMakeLists.txt:436 (find_package)

这是文件CMakeLists.txt的一部分,其中出现错误:------

#
# OpenSSL
#
if (WITH_SSL)
    message("Compiling with SSL support")

    if (USE_CYASSL)
        # Use CyaSSL as OpenSSL replacement.
        # TODO: Add a find_package command for this also.
        message("CyaSSL include dir: ${CYASSL_INCLUDE_DIRS}")
        message("CyaSSL libraries: ${CYASSL_LIB}")

        # Additional to the root directory we need to include
        # the cyassl/ subdirectory which contains the OpenSSL
        # compatability layer headers.
        foreach(inc ${CYASSL_INCLUDE_DIRS})
            include_directories(${inc} ${inc}/cyassl)
        endforeach()

        list(APPEND LIB_LIST ${CYASSL_LIB})
    else()
        # TODO: Add support for STATIC also.
        find_package(OpenSSL REQUIRED)

        message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
        message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")

        include_directories(${OPENSSL_INCLUDE_DIR})
        list(APPEND LIB_LIST ${OPENSSL_LIBRARIES})
    endif()
endif(WITH_SSL)

http://www.opensource.apple.com/source/OpenSSL/OpenSSL-7.1/openssl/INSTALL?txt
现在我已经在这里安装了Openssl:

ssl header is here   -- > /usr/local/ssl/include/openssl/
ssl library is here  -- > /usr/local/ssl/lib/libssl.a
                          /usr/local/ssl/lib/libcrypto.a
openssl is here      -- > /usr/local/ssl/bin

我已将.profile设置为:----

export LD_LIBRARY_PATH=/usr/local/ssl/include/openssl:/usr/lib:/usr/local/lib:/usr/lib/pkgconfig:/usr/local/include/wx-2.8/wx:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=/usr/lib/pkgconfig
export OPENSSL_ROOT_DIR=/usr/local/ssl
export OPENSSL_LIBRARIES=/usr/local/ssl/lib/

PATH = /usr/local/ssl/bin:$PATH

如何解决此错误?

编辑:-
得到这个错误

/usr/local/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x10): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x24): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x30): undefined reference to `dlclose'

Answers:


302

我遇到了同样的问题(openssl),这在Ubuntu 14.04.1 LTS上对我有用。该解决方案与Ubuntu 18.04相同(已测试)。

sudo apt-get install libssl-dev

20
这应该被接受的答案!感谢您的解决方案!
Mirakurun

1
同样适用于Ubuntu 16.04 LTS。
法尔科

9
这个软件包openssl-devel在Centos 7上被调用,所以您可以这样做sudo yum install openssl-devel
user2888798

2
这不再起作用了;至少不是在Ubuntu 18.04上。
阿斯特丽德

5
@Astrid我能够使其在Ubuntu 18.04中工作
Chau Giang



20

请从以下链接安装openssl:
https//code.google.com/p/openssl-for-windows/downloads/list,
然后在下面设置变量:

OPENSSL_ROOT_DIR=D:/softwares/visualStudio/openssl-0.9.8k_WIN32
OPENSSL_INCLUDE_DIR=D:/softwares/visualStudio/openssl-0.9.8k_WIN32/include
OPENSSL_LIBRARIES=D:/softwares/visualStudio/openssl-0.9.8k_WIN32/lib

就像魅力一样,谢谢!我能够从您提到的链接中提取下载的zip文件。之后,我只添加了-DOPENSSL_ROOT-DIR =“ C:/ Path / To / Extracted / Files”。
查理·维耶拉德

5
现在这已经过时了,使用起来可能很危险。openssl网站具有指向提供二进制文件的2个站点的链接。这似乎是与安全相关的库的问题。但是,设置类似的值也应该与其他二进制下载一起使用。
2015年

在Windows上与-DBUILD_TESTING=OFF -DCMAKE_USE_OPENSSL=ON
Florida

16

同样的问题,并使用以下命令将其修复在我的centos 6.5上。

yum install openssl-devel

11

sudo apt install libssl-dev 适用于Ubuntu 18.04。


2
您可能可以提供有关找到的解决方案的更多详细信息
XavM

9

如果可以使用pkg-configpkg_search_module()可以为您找到OpenSSL。

# Search OpenSSL
find_package(PkgConfig REQUIRED)
pkg_search_module(OPENSSL REQUIRED openssl)

if( OPENSSL_FOUND )
    include_directories(${OPENSSL_INCLUDE_DIRS})
    message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
else()
    # Error; with REQUIRED, pkg_search_module() will throw an error by it's own
endif()

target_link_libraries(${YOUR_TARGET_HERE} ${OPENSSL_LIBRARIES})

4

您在cmake模块中具有FindOpenSSL.cmake文件(路径usr / shared.cmake-3.5 / modules)#搜索OpenSSL

 find_package(OpenSSL REQUIRED) 
if( OpenSSL_FOUND )
    include_directories(${OPENSSL_INCLUDE_DIRS})
    link_directories(${OPENSSL_LIBRARIES})
    message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")

target_link_libraries(project_name /path/of/libssl.so /path/of/libcrypto.so)

4

给Fedora 27用户的注释:我必须安装openssl-devel软件包才能cmake成功运行。

sudo dnf install openssl-devel


4

出于娱乐目的,请为OP的问题发布替代的工作答案:

cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/ -DOPENSSL_CRYPTO_LIBRARY=/usr/local/opt/openssl/lib/

1

@Morwenn是正确的。您需要配置openssl DIR。在此之前,您可能需要确保拥有它。您应该检查是否有。第一次运行openssl version,然后如果可以win + r运行就可以运行,openssl 并且您会找到核心目录,因为它在系统中可能未命名为openssl。

在此处输入图片说明

在此处输入图片说明


0

这是我添加的CMakeList.txt(有效的):


# https://cmake.org/cmake/help/latest/command/find_package.html
# in the above link, it states:
# "In Module mode, CMake searches for a file called Find<PackageName>.cmake. 
#  The file is first searched in the CMAKE_MODULE_PATH, then among the Find 
#  Modules provided by the CMake installation. If the file is found, it is
#  read and processed by CMake. It is responsible for finding the package,
#  checking the version, and producing any needed messages. Some find-modules
#  provide limited or no support for versioning; check the module documentation."
#
# FindOpenSSL.cmake can be found in path/to/cmake/Modules
#
# https://cmake.org/cmake/help/latest/module/FindOpenSSL.html
#

find_package(OpenSSL REQUIRED)
if (OPENSSL_FOUND)
  # Add the include directories for compiling
  target_include_directories(${PROJECT_NAME} PUBLIC ${OPENSSL_INCLUDE_DIR})

  # Add the static lib for linking
  target_link_libraries(${PROJECT_NAME} OpenSSL::SSL OpenSSL::Crypto)

  message(STATUS "Found OpenSSL ${OPENSSL_VERSION}")

else()

  message(STATUS "OpenSSL Not Found")

endif()
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.