CMake not able to find OpenSSL library
OpensslCmakeOpenssl Problem Overview
I am trying to install a software that uses cmake to install itself. When I run cmake ..
on the command line, it gives me following error in the CMakeLists.txt
on the line that says find_package(OpenSSL REQUIRED)
:
-- 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 the file CMakeLists.txt
where the error is coming from:
#
# 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)
I have OpenSSL installed 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 in my .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
How can I resolve this error?
EDIT:
Now I am 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'
Openssl Solutions
Solution 1 - Openssl
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
Solution 2 - Openssl
fixed it on macOS using
brew install openssl
cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib
Solution 3 - Openssl
If you're using Ubuntu, run sudo apt install libssl-dev
.
Solution 4 - Openssl
Same problem, and fixed it on my centos 6.5 using the following command.
yum install openssl-devel
Solution 5 - Openssl
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
Solution 6 - Openssl
sudo apt install libssl-dev
works on ubuntu 18.04.
Solution 7 - Openssl
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})
Solution 8 - Openssl
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/
Solution 9 - Openssl
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()
Solution 10 - Openssl
As mentioned by others, on Ubuntu you should run
sudo apt install libssl-dev
But for me that was not enough, because although the libraries needed for building were installed, they still could not be found. What I had to install in addition was
sudo apt install pkg-config
Solution 11 - Openssl
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)
Solution 12 - Openssl
If you are using macOS then follow the below steps.
brew upgrade openssl
brew link --force openssl
pkg-config --modversion openssl
#1.1.1l
Clear the cmake build
folder and rerun the cmake ..
Solution 13 - Openssl
Note for Fedora 27 users: I had to install openssl-devel
package to run the cmake
successfully.
sudo dnf install openssl-devel
Solution 14 - Openssl
@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.
Solution 15 - Openssl
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()
Solution 16 - Openssl
On WSL I still got the error after running sudo apt install libssl-dev
.
I had to run whereis openssl
and then updated the commented out lines in CMakeCache.txt
:
#OPENSSL_CRYPTO_LIBRARY:FILEPATH=OPENSSL_CRYPTO_LIBRARY-NOTFOUND
OPENSSL_CRYPTO_LIBRARY:FILEPATH=/usr/bin/openssl
#OPENSSL_INCLUDE_DIR:PATH=OPENSSL_INCLUDE_DIR-NOTFOUND
OPENSSL_INCLUDE_DIR:PATH=/usr/include/openssl
Solution 17 - Openssl
The answer actually depends on the status of your system and the program you are using cmake
on. Based on the second errors you are getting, you might need an extra openssl
package that is not currently installed on your system. You can search packages using the aptitude search
command. I recommend searching for "ssl" rather than "openssl" as the packages sometimes don't contain the word "open".
Another thing you can do to check which packages to install is to find if the manual or documentation of the product you are installing contains information about which packages to install.
Like the other posts comment, one of such packages is libssl-dev, but your program might need some other packages as well.
Solution 18 - Openssl
In addition to the accepted answer, I'm posting some extra information that could have saved me two full days' work and a complete CMake tear up. My machine runs Ubuntu 20.04
Installing libssl-dev as suggested includes two libraries: libssl and libcrypto. The find_package directive in my cmake project was eliminating the reference errors in my project, but it still couldn't find the libraries. That's because all of the accepted answers around tell you to use these lines:
> find_package(OpenSSL REQUIRED)
> target_link_libraries(MyExecutable OpenSSL Crypto)
Cmake will look for libraries with names libOpenSSL and libCrypto. Both failed due to capitalization, and libopenssl doesn't exist because the file is actually just named libssl. Indeed, check the contents of the libssl-dev package by using: > apt-file list libssl-dev
So, in my case, the solution was to use this cmake directive instead: > target_link_libraries(MyExecutable ssl crypto)