242

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'
Olivia Stork
  • 4,660
  • 5
  • 27
  • 40
Allan
  • 2,971
  • 4
  • 24
  • 28

18 Answers18

588

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
Leos313
  • 5,152
  • 6
  • 40
  • 69
Arwen
  • 6,005
  • 2
  • 10
  • 5
86

fixed it on macOS using

brew install openssl
cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib
Josh Correia
  • 3,807
  • 3
  • 33
  • 50
qin
  • 1,627
  • 15
  • 22
  • 5
    `OPENSSL_LIBRARIES` is an output variable, not an input. See https://github.com/Kitware/CMake/blob/300979e7889b34d61803675c560fe450c7404447/Modules/FindOpenSSL.cmake – Simon Warta Aug 11 '17 at 13:33
  • 2
    Pro tip: this is using the `-D${Variiable name}` as in this answer causes cmake to cache the value, so you only have to call `cmake` with these variables once at the command line once in the project. Every build after that will use the cached value, so you don't have to add this to cmake every time (unless you delete your build directory) – Jthorpe Sep 15 '22 at 22:10
34

Same problem, and fixed it on my CentOS 6.5 using the following command:

yum install openssl-devel
Josh Correia
  • 3,807
  • 3
  • 33
  • 50
xavierzhao
  • 780
  • 9
  • 18
24

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
bummi
  • 27,123
  • 14
  • 62
  • 101
appapurapu
  • 602
  • 7
  • 6
  • Works like a charm, thanks! I was able to extract the zip file downloaded form the link you mentioned. After that I just added -DOPENSSL_ROOT-DIR="C:/Path/To/Extracted/Files". – Charlie Vieillard Apr 09 '15 at 08:05
  • 11
    This is now very out of date and probably dangerous to use. The openssl website has links to 2 sites that provide binaries. That's seems to be the problem with security related libs like this. However, setting the values like that should work with the other binary downloads too. – Beached Nov 10 '15 at 21:12
  • Worked on Windows with `-DBUILD_TESTING=OFF -DCMAKE_USE_OPENSSL=ON` – Florida Apr 08 '19 at 15:03
  • 1
    Setting the environment variables above allowed Cmake to finish successfully but then I got compile errors. However I downloaded the Win64 OpenSSL v1.1.1k libraries at https://slproweb.com/products/Win32OpenSSL.html which are more up to date and then it worked thanks!. I also set env variable OPENSSL_CONF to point to openssl.cfg – Gary Shaw May 16 '21 at 18:29
22

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

Shravan40
  • 8,922
  • 6
  • 28
  • 48
16

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
Josh Correia
  • 3,807
  • 3
  • 33
  • 50
Excodibur
  • 179
  • 1
  • 2
11

Just for fun, I'll 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/
Josh Correia
  • 3,807
  • 3
  • 33
  • 50
user7986267
  • 645
  • 1
  • 7
  • 10
10

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})
ollo
  • 24,797
  • 14
  • 106
  • 155
7

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()
OSP
  • 1,458
  • 1
  • 14
  • 15
6

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)
sekhar
  • 91
  • 1
  • 5
  • After replaced OPENSSL_INCLUDE_DIRS with OPENSSL_INCLUDE_DIR, worked fine. win10 + vs2019 + cmake 3.20.3 + slproweb.com(Win32OpenSSL-1_1_1k.exe) – doufu Jun 09 '21 at 03:04
5

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

sudo dnf install openssl-devel

ttarczynski
  • 949
  • 1
  • 10
  • 19
5

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)

Jeff
  • 51
  • 1
  • 1
  • thanks, one more reason to hate ubuntu. Their packahe naming is inconsistant and stupit, archlinux is nice – 0xB00B Jun 11 '22 at 16:13
2

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
IAmCoder
  • 3,179
  • 2
  • 27
  • 49
1

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

enter image description here

enter image description here

Shihe Zhang
  • 2,641
  • 5
  • 36
  • 57
1

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()
1

I'm using macOS and I preferred to set the environmental variable OPENSSL_ROOT_DIR

brew install openssl@1.1
export OPENSSL_ROOT_DIR=/usr/local/opt/openssl@1.1/
0

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.

0

I had to change the -DXMRIG_DEPS from a relative path to a full path.

-DXMRIG_DEPS=./xmrig-deps/gcc/x64

change to:

-DXMRIG_DEPS=C:/Users/dean/xmrig-deps/gcc/x64

deanqx
  • 75
  • 1
  • 7