More recent OpenSSL versions (the 1.1.x series I think) slightly changed the formatting of how the version number was specified in the opensslv.h header. This caused CMake's version parsing code in its FindOpenSSL.cmake module to fail, which was then fixed around CMake 3.5.0. Furthermore, from OpenSSL 1.1.0, the library names on Windows are closer to their Unix counterparts and are named libcrypto and libssl (possibly with further suffixes) instead of the old names libeay32 and ssleay32. CMake 3.7.0 contained the update to account for this library name change. As a result of these two changes and fixes, if you want to use OpenSSL 1.1.0 or later with a CMake project, you should probably be using CMake 3.7.0 or later.

Answer from Craig Scott on Stack Overflow
🌐
GitHub
github.com › raspberrypi › rpi-imager › issues › 351
Can't get OpenSSL detected on windows build · Issue #351 · raspberrypi/rpi-imager
February 6, 2022 - CMake Error at C:/Program Files/CMake/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message): Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY) (found version "1.1.1i") Call Stack ...
Author   raspberrypi
Discussions

CMake: Could NOT find OpenSSL
You switched accounts on another tab or window. Reload to refresh your session. ... I am trying to get started with Simple-Web-Server over at https://gitlab.com/eidheim/Simple-Web-Server ... CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/FindPackageHandleStandardArgs.cmake:137 (message): Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR ... More on github.com
🌐 github.com
7
September 3, 2018
[OpenSSL] Explicitly set OPENSSL_ROOT_DIR
Explicitly setting OPENSSL_ROOT_DIR to point to vcpkg's OpenSSL directory usually resolves the issue. More on github.com
🌐 github.com
10
March 15, 2021
Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR)
Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. ... Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR)#26 More on github.com
🌐 github.com
11
February 20, 2022
[Question] What am I doing wrong?
You've got a few things going on here (and your formatting is wonky, so I might even be missing something else). You should only need to set OPENSSL_ROOT_DIR. The find_package() call, if successful, will set OPENSSL_INCLUDE_DIR. That said, FindOpenSSL.cmake clearly isn't finding what it wants. It's looking for openssl/ssl.h in a plethora of places, which should include that root you did set. Is there a /usr/local/Cellar/openssl/1.0.2s/include/openssl/ssl.h? You should also use the actual target names that those Find calls are setting up. The variables are only for backwards compatibility with old builds. To wit: Threads::Threads OpenSSL::SSL OpenSSL::Crypto Boost::system CURL::libcurl You shouldn't need the target_include_directories assuming your CMake is reasonably new. You'll get it automatically from linking against Boost::system. More on reddit.com
🌐 r/cmake
1
1
December 8, 2019
🌐
Kontext
kontext.tech › home › blogs › c和c++ › cmake build error - could not find openssl on windows 10
CMake Build Error - Could not Find OpenSSL on Windows 10 - Kontext Labs
July 31, 2020 - In my system, OpenSSL is installed via vcpkg and installation folder is: C:/vcpkg/installed/x64-windows-static. Thus to fix this issue, I just need to change the command line to the following: cmake . -DOPENSSL_ROOT_DIR="C:/vcpkg/installed/x64-windows-static"
🌐
GitHub
github.com › Microsoft › vcpkg › issues › 4219
CMake: Could NOT find OpenSSL · Issue #4219 · microsoft/vcpkg
September 3, 2018 - You switched accounts on another tab or window. Reload to refresh your session. ... I am trying to get started with Simple-Web-Server over at https://gitlab.com/eidheim/Simple-Web-Server ... CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/FindPackageHandleStandardArgs.cmake:137 (message): Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR ...
Author   microsoft
🌐
CMake
cmake.org › cmake › help › v3.6 › module › FindOpenSSL.html
FindOpenSSL — CMake 3.6.3 Documentation
... The OpenSSL crypto library. ... The OpenSSL SSL library. ... All OpenSSL libraries. ... This is set to $major.$minor.$revision$patch (e.g. 0.9.8s). Set OPENSSL_ROOT_DIR to the root directory of an OpenSSL installation. Set OPENSSL_USE_STATIC_LIBS to TRUE to look for static libraries.
🌐
GitHub
github.com › microsoft › vcpkg › issues › 16709
[OpenSSL] Explicitly set OPENSSL_ROOT_DIR · Issue #16709 · microsoft/vcpkg
March 15, 2021 - Explicitly setting OPENSSL_ROOT_DIR to point to vcpkg's OpenSSL directory usually resolves the issue.
Author   microsoft
🌐
Srtlab
srtlab.github.io › srt-cookbook › getting-started › build-on-windows.html
Build on Windows - SRT CookBook
If any of the is not found, you can define the following variables to help CMake find them: OPENSSL_ROOT_DIR=<path to OpenSSL installation> OPENSSL_LIBRARIES=<path to all the openssl libraries to link> OPENSSL_INCLUDE_DIR=<path to the OpenSSL include dir> PTHREAD_INCLUDE_DIR=<path to where ...
🌐
Narkive
libssh2-devel.cool.haxx.narkive.com › uLG8aLNj › problems-building-under-windows
problems building under Windows - libssh2-devel@cool.haxx.se
TLDR: CMake sort of works CMake (on Windows) is notoriously stubborn when it comes to finding libraries. I had to upgrade to CMake 3.4.1 (was 3.2.2) to be able to manually specify the location of the OpenSSL library: -D"OPENSSL_ROOT_DIR=/php-sdk/win64build.vc14" for 64-bits VC14 libs ...
Find elsewhere
🌐
CMake
cmake.org › pipermail › cmake › 2014-May › 057587.html
[CMake] FindOpenSSL choosing unexpected OpenSSL install on Windows
May 15, 2014 - It isn't clear to me why FindOpenSSL would care about the binary build if OPENSSL_ROOT_DIR has been set: if (WIN32) # http://www.slproweb.com/products/Win32OpenSSL.html set(_OPENSSL_ROOT_HINTS ${OPENSSL_ROOT_DIR} "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL ...
🌐
GitHub
github.com › janbar › openssl-cmake › issues › 26
Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR) · Issue #26 · janbar/openssl-cmake
February 20, 2022 - Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. ... Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR)#26
Author   janbar
🌐
Reddit
reddit.com › r/cmake › [question] what am i doing wrong?
r/cmake on Reddit: [Question] What am I doing wrong?
December 8, 2019 -

(I'm new to build systems and adding libraries, if I have provided insufficient information let me know in the comments.)
I've installed openssl lib using brew to /usr/local/Cellar/openssl (macOS) and when I compile my project I get an error:

CMake Error at /Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.15/Modules/FindPackageHandleStandardArgs.cmake:137 (message): Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_INCLUDE_DIR)

CMakeLists.txt:

cmake_minimum_required(VERSION 3.15) project(recost)

set(CMAKE_CXX_STANDARD 20)

add tgbot-cpp

add_subdirectory(lib/tgbot-cpp)

add boost

set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "/usr/local/Cellar/boost/1.70.0/include") set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "/usr/local/Cellar/boost/1.70.0/lib")

add openssl

set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "/usr/local/Cellar/openssl/1.0.2s/include") set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "/usr/local/Cellar/openssl/1.0.2s/lib")

set(OPENSSL_ROOT_DIR "/usr/local/Cellar/openssl/1.0.2s/") set(OPENSSL_INCLUDE_DIR "/usr/local/Cellar/openssl/1.0.2s/include")

set(Boost_USE_MULTITHREADED ON)

find_package(Threads REQUIRED) find_package(OpenSSL REQUIRED) find_package(Boost COMPONENTS system REQUIRED) find_package(CURL) include_directories(/usr/local/include ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR})

set(BOOST_ROOT /usr/local/Cellar/boost/) set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME ON) find_package(Boost REQUIRED COMPONENTS system)

target_include_directories(${Boost_INCLUDE_DIRS})

target_link_libraries(recost TgBot ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} ${Boost_LIBRARIES} ${CURL_LIBRARIES})

add_executable(recost main.cpp)

🌐
Reddit
reddit.com › r/cmake › cmake cant find openssl
r/cmake on Reddit: CMake cant find OpenSSL
August 21, 2024 -
cmake_minimum_required(VERSION 3.28)
project(FindOpenSSL)
set(CMAKE_CXX_STANDARD 23)
add_executable(FindOpenSSL main.cpp)
set(OPENSSL_ROOT_DIR "C:/Program Files/OpenSSL-Win64")
find_package(OpenSSL REQUIRED)cmake_minimum_required(VERSION 3.28)
project(FindOpenSSL)
set(CMAKE_CXX_STANDARD 23)
add_executable(FindOpenSSL main.cpp)
set(OPENSSL_ROOT_DIR "C:/Program Files/OpenSSL-Win64")
find_package(OpenSSL REQUIRED)

I have it as can bee seen here

And it works

I'm not feeling well, I feel extremely tired, please help. I'm using Clion

🌐
CMake
cmake.org › cmake › help › latest › module › FindOpenSSL.html
FindOpenSSL — CMake 4.3.3 Documentation
This variable is only defined if found OpenSSL version is at least 0.9.8 and the platform is MSVC. This module accepts the following variables to control the search behavior: ... Set to the root directory of an OpenSSL installation to search for the OpenSSL libraries in custom locations.
Top answer
1 of 4
103

You could also run this command to identify in which directory it's installed to.

openssl version -d
2 of 4
26

which is the openssldir?

By default, the OpenSSL directory is /usr/local/ssl. If you perform a config without --prefix and without --openssldir, that's what you get by default.

Headers will be located in /usr/local/ssl/include/openssl and libraries will be located in /usr/local/ssl/lib.

You should prefer --openssldir, and avoid clever tricks like --prefix=/usr to overwrite a distro's copy of OpenSSL.

If you want to provide a more up to date version of OpenSSL, then look into building a custom package (Personal Package Archive (PPA)) as described at Override Distro Package with Custom Package?.

I'm working on OS X 10.8.5 at the moment. Here's what my /usr/local/ssl looks like (I use one additional directory path on --openssldir due to multiple OpenSSL builds):

$ ls /usr/local/ssl/
android-14    darwin    macosx-x64
android-18    ios       macosx-x86

the --with-openssl is available. Should this point to the OpenSSL compilation option given to prefix or openssldir?

Yes (but it depends). I've worked with a lot of projects that don't append include and lib properly.

Often times those libraries with --with-openssl are broken in subtle ways. For example, suppose you do the following:

export CFLAGS="-I/usr/local/ssl/include"
export LDFLAGS="/usr/local/ssl/lib"
./config ... --with-openssl=/usr/local/ssl
make
sudo make install

In the above, you will compile and link against the gear in /usr/local/ssl. Then, when you execute your program, it will link against the shared object in /usr/lib, and not the shared object in /usr/local/ssl/lib.

If your distro provides 0.9.8 and you have 1.0.1 in /usr/local/ssl, you will get a lot of unexplained crashes that make no sense. Be vigilant for this issue on OS X because Apple provides 0.9.8.

If you and the distro are both providing something binary compatible (like 1.0.1), then you will be missing functionality without explanation. For example, your version of OpenSSL will have TLS 1.1 and 1.2 enabled, while Ubuntu's version will have TLS 1.1 and 1.2 disabled (Ubuntu priot to 14 built with -DOPENSSL_NO_TLS1_2_CLIENT). And you'll wonder why you cannot connect using TLS 1.2.

If you are compiling on OS X, then you will find OS X silently discards your request to perform static linking (i.e., -Bstatic -lcrypto -lssl). The linker will always use the shared object if available (even on iOS, where its not allowed!). And it will silently ignore your -rpath, too. And forget LD_LIBRARY_PATH because its not honored (you have to use DYLD_LIBRARY_PATH per dyld(1)).

The easiest way to cope with OS X is to:

cd <project>
grep -R "-lcrypto" *
<replace all occurences of -lcrypto with /usr/local/ssl/lib/libcrypto.a>
grep -R "-lssl" *
<replace all occurences of -lssl with /usr/local/ssl/lib/libssl.a>

Archives are just like object files (they are a collection of object files), so you don't even need the -l.

When forcing static linking as above, you don't have to worry about the linker silently discarding your requests or doing things you don't expect. The same works on Linux, too. As a matter of fact, I always use my own version of OpenSSL, and I always do what I described because I got tired of fighting with the various tools (its not only ld, its Eclipse and friends, too).

🌐
GitHub
github.com › eclipse-paho › paho.mqtt.c › issues › 276
Error while building with cmake in cygwin windows 7 · Issue #276 · eclipse-paho/paho.mqtt.c
May 10, 2017 - You switched accounts on another tab or window. Reload to refresh your session. ... Whenever i am trying to build using cmake i get this error-: 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)
Author   eclipse-paho
🌐
DebugPoint
debugpoint.com › home › tutorials › how to fix: could not find openssl error in ubuntu and other linux
[Fixed] Could NOT find OpenSSL Error in Ubuntu and Other Linux
February 15, 2023 - -- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR) (Required is at least version "0.9.7") -- Could NOT find WolfSSL (missing: WOLFSSL_LIBRARY WOLFSSL_INCLUDE_DIR) (Required is at least version "3.4") -- Could NOT find MbedTLS (missing: MBEDTLS_LIBRARY MBEDTLS_INCLUDE_DIR) (Required is at least version "1.3") CMake Error at CMakeLists.txt:258 (message): Unable to find any supported crypto library.
🌐
GitHub
github.com › microsoft › cpprestsdk › issues › 1413
CMake error if OPENSSL_ROOT_DIR is not set · Issue #1413 · microsoft/cpprestsdk
May 9, 2020 - You switched accounts on another tab or window. Reload to refresh your session. ... CMake Error at Release/cmake/cpprest_find_openssl.cmake:40 (list): list GET given empty list Call Stack (most recent call first): Release/cmake/cpprest_find_websocketpp.cmake:18 (cpprest_find_openssl) Release/src/CMakeLists.txt:68 (cpprest_find_websocketpp) -- OPENSSL_ROOT_DIR = -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Checking for one of the modules 'openssl' -- Found OpenSSL: /opt/local/lib/libcrypto.dylib (found suitable version "1.1.1g", minimum required is "1.0.0")
Author   microsoft