CMake not able to find OpenSSL library

前端 未结 13 1723
一生所求
一生所求 2020-11-27 09:53

I am trying to install a software, which uses cmake to install itself, when i give at commandlin cmake ..
it gives me following error in this file, CMakeLists.txt -----

相关标签:
13条回答
  • 2020-11-27 10:20

    Note for Fedora 27 users: I had to install openssl-devel package to run the cmake successfully.

    sudo dnf install openssl-devel

    0 讨论(0)
  • 2020-11-27 10:20

    This is what I added in the CMakeList.txt (which worked):

    
    # 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()
    
    0 讨论(0)
  • 2020-11-27 10:24

    I had the same problem (openssl) and this worked for me on Ubuntu 14.04.1 LTS. The solution is the same up to Ubuntu 18.04 (tested).

    sudo apt-get install libssl-dev
    
    0 讨论(0)
  • 2020-11-27 10:25

    you are having the FindOpenSSL.cmake file in the cmake module(path usr/shared.cmake-3.5/modules) # Search 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)
    
    0 讨论(0)
  • 2020-11-27 10:26

    Same problem, and fixed it on my centos 6.5 using the following command.

    yum install openssl-devel
    
    0 讨论(0)
  • 2020-11-27 10:30

    If you can use pkg-config: pkg_search_module() can find OpenSSL for you.

    # 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})
    
    0 讨论(0)
提交回复
热议问题