CMake not able to find OpenSSL library

匿名 (未验证) 提交于 2019-12-03 02:13:02

问题:

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 -------- line ---> find_package(OpenSSL REQUIRED) :--

 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) 

Here is the part of file CMakeLists.txt, where error is comming :------

# # 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
Now i have installed Openssl, here :----

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 

I have set my .profile as :----

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 

How to resolve this error ?

edit :--
Getting this error

/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' 

回答1:

It is a common misunderstanding: CMake does not need environment variables to know where the library and include dir are but CMake variables.

Since CMake can not find your OpenSSL lib and include directory, you will have to manually tell him where they are with its command line when you call it. Use the option -D to set constants in CMake from the command line. You will need to set the constants OPENSSL_ROOT_DIR and OPENSSL_LIBRARIES since they are the one triggering the error.

cmake -DOPENSSL_ROOT_DIR=/usr/local/ssl -DOPENSSL_LIBRARIES=/usr/local/ssl/lib 


回答2:

I had the same problem (openssl) and this worked for me on Ubuntu 14.04.1 LTS

sudo apt-get install libssl-dev 


回答3:

fixed it on macOS using

brew install openssl cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib 


回答4:

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 


回答5:

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}) 


回答6:

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

yum install openssl-devel 


回答7:

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) 


回答8:

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



回答9:

@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.



回答10:

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

sudo dnf install openssl-devel



回答11:

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/ 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!