273

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'
1
  • Did you figure it out? What did you do to get to the "Now I am getting"? Is there a file /usr/lib/pkgconfig/openssl.pc ? :) Commented Jan 10, 2024 at 7:26

20 Answers 20

629

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
Sign up to request clarification or add additional context in comments.

1 Comment

This package is called openssl-devel on Centos 7, so you would do sudo yum install openssl-devel
91

fixed it on macOS using

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

2 Comments

OPENSSL_LIBRARIES is an output variable, not an input. See github.com/Kitware/CMake/blob/…
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)
41

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

Comments

36

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

yum install openssl-devel

Comments

31

Please install openssl from below link:
https://code.google.com/archive/p/openssl-for-windows/downloads
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

4 Comments

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".
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.
Worked on Windows with -DBUILD_TESTING=OFF -DCMAKE_USE_OPENSSL=ON
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 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
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 ..

5 Comments

I ran into this today and this solution worked for me. Configuration reference: macOS Monterey running on Apple Silicon.
This worked for me after having issues on my M1 mac with intel brew installed. Thank you.
Worked on macOS with Ventura 13.1 (22C65)
The brew link tip helped me solve my problem, I just had to unlink the unwanted version and then link the openssl version I needed to use
This works for me, thank you very much! My macbook pro's OS version is 26.0.1 with Apply M3.
13

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/

3 Comments

I think OPENSSL_CRYPTO_LIBRARY should point to /usr/local/opt/openssl/lib/libcrypto.dylib instead.
The only working answer.
in my case on linux 8, the same as Adam Hunyadi except ..../lib/libcrypto.so
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})

Comments

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)

1 Comment

After replaced OPENSSL_INCLUDE_DIRS with OPENSSL_INCLUDE_DIR, worked fine. win10 + vs2019 + cmake 3.20.3 + slproweb.com(Win32OpenSSL-1_1_1k.exe)
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()

Comments

5

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

sudo dnf install openssl-devel

Comments

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)

1 Comment

thanks, one more reason to hate ubuntu. Their packahe naming is inconsistant and stupit, archlinux is nice
3

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

Comments

3

Meet the same problem after 5 years...

The Problem was solved by set PKG_CONFIG_PATH to be /usr/local/ssl/lib/pkgconfig.

1 Comment

Just a small not it should be ENV{PKG_CONFIG_PATH} for this to work
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

Comments

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

Comments

1

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

brew install [email protected]
export OPENSSL_ROOT_DIR=/usr/local/opt/[email protected]/

1 Comment

mine was at /opt/homebrew/opt/[email protected]
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.

Comments

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

Comments

-1

I got the same error with a problem of cmake version. On windows, use visual cmake.

2 Comments

This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review
@Sam The intro is unfortunate, but this tries to answer the question with "use visual cmake", doesn't it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.