Unable to compile and link with openssl with cmake on Windows
Asked Answered
F

1

6

I am trying to make my code compile on Windows, and read since a couple of days all opened discussions on stackoverflow on the subject, without finding a solution.

I installed openssl with choco in a terminal with privileges:

choco install openssl -y

and I notice that it gets installed to C:\Program Files\OpenSSL-Win64.

Here is the content of the openssl directory:

 dir "$OPENSSL_ROOT_DIR"
acknowledgements.txt  authors.txt  bin  c_rehash.pl  changes.txt  exp  faq.txt  include  lib  libcrypto-3-x64.dll  libssl-3-x64.dll  license.txt  news.txt  readme.txt  start.bat  tests  unins000.dat  unins000.exe

In my CMakeLists.txt I have this relevant line:

find_package(OpenSSL REQUIRED)

Nothing very special here. And of course, it cannot be that easy:

  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 "3.2.1")

So, I deleted the CMake cache, add the OPENSSL_ROOT_DIR in my PATH, restarted the shell, make sure that my variable OPENSSL_ROOT_DIR is correctly set, re-launch cmake, and same error.

I use cmake 3.28.3 and openssl version installed is 3.2.1.

In GitHub actions the openssl library is installed by default for runner windows-latest, and cmake can find it directly. However, I have the exact similar issue for curl, if I install it manually and provide the correct variables to cmake, it cannot find curl.

It works out of the box on my Ubuntu system, just installing libcurl4-gnutls-dev libssl-dev, I don't need to care about setting any variable whatsoever. And it worked also on GitHub actions before the latest windows-latest runner last week.

Fulbert answered 29/2, 2024 at 10:12 Comment(7)
Can you try something like cmake -DOPENSSL_ROOT_DIR=/path/to/openssl ...?Leftover
@Leftover Yes, tried that as well. It does not change anything. Also, I made sure by echo $OPENSSL_ROOT_DIR that my variable is correctly set.Irreparable
Does your openssl directory contain libcrypto? CMake doesn't seem to find libcrypto in that directory.Leftover
I just updated the description adding the contents of openssl root directory. It contains libcrypto-3-x64.dllIrreparable
Maybe you should also raise an issue in OpenSSL's Github repo, just in case.Leftover
Run cmake with additional option --debug-find. That way CMake will print paths which are checked for find specific libraries. From such output you could find out which paths are checked for find the library corresponding to OPENSSL_CRYPTO_LIBRARY.Goiter
Try updating to cmake 3.29.0. I got the same error and upgrading appears to resolve. The issue may be addressed by gitlab.kitware.com/cmake/cmake/-/issues/25702.Levantine
R
1

I solved the problem by going to the OpenSSL install directory and simply copying the files libcrypto.lib and libssl.lib from YOUR_OPENSSL_INSTALL_DIR/lib/VC/x64/MD to YOUR_OPENSSL_INSTALL_DIR/lib/.

I suspect this happens because the latest cmake version (3.30.1, when I write this) expects those files only in the lib/ dir.

Rossiter answered 30/7, 2024 at 14:57 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.