Cyberithub

[Solved]: "CMake could not find OpenSSL" error

Advertisements

In this article, we will see how to solve cmake could not find openssl error. The other day when I was trying to install an application through source code, I noticed "CMake could not find OpenSSL" error on my system. It is not very uncommon to get this error in case you don't have all the prerequisites installed in your system. Let me explain this through a recent example. Few days back, when I was trying to install snort 3 on my Ubuntu 22.04 LTS system, during configuration check it showed "CMake could not find OpenSSL" error on the output.

While I was quite sure that all the prerequisites to snort 3 was already available in my system but after looking closely I noticed the root cause of the error. So at this time, I thought to write about this in case same thing happens to any of you as well. Probably it will help you save lot of troubleshooting time. I would suggest you to go through below given solution to fix the problem.

 

[Solved]: "CMake could not find OpenSSL" Error

[Solved]: "CMake could not find OpenSSL" Error

Also Read: [Solved]: "Can't Find luajit" or No package 'luajit' found

To explain further, when I tried to configure source code of snort 3 application by running ./configure_cmake.sh script then it showed "cmake could not find openssl" error on the output as shown below.

cyberithub@ubuntu:~/snort3-3.1.71.0$ ./configure_cmake.sh
./configure_cmake.sh: 486: [: Illegal number:
Build Directory : build
Source Directory: /home/cyberithub/snort3-3.1.71.0
-- The CXX compiler identification is Clang 14.0.0
-- The C compiler identification is GNU 11.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2")
-- Checking for module 'libdaq>=3.0.12'
-- Found libdaq, version 3.0.12
-- Found DAQ: /usr/local/lib/libdaq.so
-- Checking for module 'libdaq_static_afpacket'
-- Found libdaq_static_afpacket, version 3.0.12
-- Checking for module 'libdaq_static_fst'
-- Found libdaq_static_fst, version 3.0.12
-- Checking for module 'libdaq_static_gwlb'
-- Found libdaq_static_gwlb, version 3.0.12
-- Checking for module 'libdaq_static_savefile'
-- Found libdaq_static_savefile, version 3.0.12
-- Checking for module 'libdaq_static_trace'
-- Found libdaq_static_trace, version 3.0.12
-- Found DNET: /usr/include
-- Found FLEX: /usr/bin/flex (found suitable version "2.6.4", minimum required is "2.6.0")
-- Checking for module 'hwloc'
-- Found hwloc, version 2.7.0
-- Found HWLOC: /usr/lib/x86_64-linux-gnu/libhwloc.so
-- Checking for module 'luajit'
-- Found luajit, version 2.1.1695653777
-- Found LuaJIT: /usr/local/lib/libluajit-5.1.so (found version "2.1.1695653777")
CMake Error at /usr/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
OPENSSL_INCLUDE_DIR) (Required is at least version "1.1.1")
Call Stack (most recent call first):
/usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.22/Modules/FindOpenSSL.cmake:574 (find_package_handle_standard_args)
cmake/include_libraries.cmake:9 (find_package)
CMakeLists.txt:27 (include)


-- Configuring incomplete, errors occurred!
See also "/home/cyberithub/snort3-3.1.71.0/build/CMakeFiles/CMakeOutput.log".

While above could occur due to multiple reasons but most of the time it occurs due to missing libssl-dev package in the system. So to fix the error, you just have to install the package using sudo apt install libssl-dev command as shown below.

cyberithub@ubuntu:~/snort3-3.1.71.0$ sudo apt install libssl-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
libluajit-5.1-2 libluajit-5.1-common
Use 'sudo apt autoremove' to remove them.
Suggested packages:
libssl-doc
The following NEW packages will be installed:
libssl-dev
0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
Need to get 2,372 kB of archives.
After this operation, 12.4 MB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libssl-dev amd64 3.0.2-0ubuntu1.10 [2,372 kB]
Fetched 2,372 kB in 3s (883 kB/s)
Selecting previously unselected package libssl-dev:amd64.
(Reading database ... 235282 files and directories currently installed.)
Preparing to unpack .../libssl-dev_3.0.2-0ubuntu1.10_amd64.deb ...
Unpacking libssl-dev:amd64 (3.0.2-0ubuntu1.10) ...
Setting up libssl-dev:amd64 (3.0.2-0ubuntu1.10) ...

After installing the package, if you run the ./configure_cmake.sh script again then you will notice that this time error disappears and you will be able to continue with the installation.

cyberithub@ubuntu:~/snort3-3.1.71.0$ ./configure_cmake.sh
./configure_cmake.sh: 486: [: Illegal number:
Build Directory : build
Source Directory: /home/cyberithub/snort3-3.1.71.0
-- The CXX compiler identification is Clang 14.0.0
-- The C compiler identification is GNU 11.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2")
-- Checking for module 'libdaq>=3.0.12'
-- Found libdaq, version 3.0.12
-- Found DAQ: /usr/local/lib/libdaq.so
-- Checking for module 'libdaq_static_afpacket'
-- Found libdaq_static_afpacket, version 3.0.12
-- Checking for module 'libdaq_static_fst'
-- Found libdaq_static_fst, version 3.0.12
-- Checking for module 'libdaq_static_gwlb'
-- Found libdaq_static_gwlb, version 3.0.12
-- Checking for module 'libdaq_static_savefile'
-- Found libdaq_static_savefile, version 3.0.12
-- Checking for module 'libdaq_static_trace'
-- Found libdaq_static_trace, version 3.0.12
-- Found DNET: /usr/include
-- Found FLEX: /usr/bin/flex (found suitable version "2.6.4", minimum required is "2.6.0")
-- Checking for module 'hwloc'
-- Found hwloc, version 2.7.0
-- Found HWLOC: /usr/lib/x86_64-linux-gnu/libhwloc.so
-- Checking for module 'luajit'
-- Found luajit, version 2.1.1695653777
-- Found LuaJIT: /usr/local/lib/libluajit-5.1.so (found version "2.1.1695653777")
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found suitable version "3.0.2", minimum required is "1.1.1")

Sometimes it is also possible that even after installing libssl-dev package, you still get the same error. In that case, it is possible that you don't have openssl package installed in your system. So to fix the error you have to install openssl package using sudo apt install openssl command as shown below.

cyberithub@ubuntu:~/snort3-3.1.71.0$ sudo apt install openssl

Hope above solution would be enough to solve your error as well as it solved mine. Please let me know your feedback in the comment box.

Leave a Comment