CMake not able to find OpenSSL library

前端 未结 13 1724
一生所求
一生所求 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:32

    @Morwenn is right. You need to config the openssl DIR. Before that you may need to make sure you have it. you should check whether you have it. first run openssl version,then if you have it you can win + r run openssl and you win find the core dir since it may not name as openssl in your system.

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

    Please install openssl from below link:
    https://code.google.com/p/openssl-for-windows/downloads/list
    then set the variables below:

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

    Just in case...this works for me. Sorry for specific version of OpenSSL, but might be desirable.

    # On macOS, search Homebrew for keg-only versions of OpenSSL
    # equivalent of # -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/ -DOPENSSL_CRYPTO_LIBRARY=/usr/local/opt/openssl/lib/
    if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
        execute_process(
            COMMAND brew --prefix OpenSSL 
            RESULT_VARIABLE BREW_OPENSSL
            OUTPUT_VARIABLE BREW_OPENSSL_PREFIX
            OUTPUT_STRIP_TRAILING_WHITESPACE
        )
        if (BREW_OPENSSL EQUAL 0 AND EXISTS "${BREW_OPENSSL_PREFIX}")
            message(STATUS "Found OpenSSL keg installed by Homebrew at ${BREW_OPENSSL_PREFIX}")
            set(OPENSSL_ROOT_DIR "${BREW_OPENSSL_PREFIX}/")
            set(OPENSSL_INCLUDE_DIR "${BREW_OPENSSL_PREFIX}/include")
            set(OPENSSL_LIBRARIES "${BREW_OPENSSL_PREFIX}/lib")
            set(OPENSSL_CRYPTO_LIBRARY "${BREW_OPENSSL_PREFIX}/lib/libcrypto.dylib")
        endif()
    endif()
    
    ...
    
    find_package(OpenSSL REQUIRED)
    if (OPENSSL_FOUND)
      # Add the include directories for compiling
      target_include_directories(${TARGET_SERVER} PUBLIC ${OPENSSL_INCLUDE_DIR})
      # Add the static lib for linking
      target_link_libraries(${TARGET_SERVER} OpenSSL::SSL OpenSSL::Crypto)
      message(STATUS "Found OpenSSL ${OPENSSL_VERSION}")
    else()
      message(STATUS "OpenSSL Not Found")
    endif()
    
    0 讨论(0)
  • 2020-11-27 10:41

    If you're using Ubuntu, run sudo apt install libssl-dev.

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

    fixed it on macOS using

    brew install openssl
    cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib
    
    0 讨论(0)
  • 2020-11-27 10:42

    Just for fun ill post an alternative working answer for the OP's question:

    cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/ -DOPENSSL_CRYPTO_LIBRARY=/usr/local/opt/openssl/lib/
    
    0 讨论(0)
提交回复
热议问题