Search code examples
windowscmakeopensslmingwmsys

CMake "Could NOT find OpenSSL" with MSYS2/mingw64 on Windows


I'm trying to compile this project on Windows using MSYS2 with mingw64, and when running cmake . I get the following output:

-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.16299.
-- Build type: Release
-- Source of Randomness: random_device
CMake Error at C:/msys64/mingw64/share/cmake-3.13/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_CRYPTO_LIBRARY) (found
  version "1.1.1b")
Call Stack (most recent call first):
  C:/msys64/mingw64/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
  C:/msys64/mingw64/share/cmake-3.13/Modules/FindOpenSSL.cmake:412 (find_package_handle_standard_args)
  CMakeLists.txt:10 (find_package)

I have OpenSSL installed, as evidenced by:

$ which openssl
/mingw64/bin/openssl

$ openssl version
OpenSSL 1.1.1b  26 Feb 2019

And the OPENSSL_CRYPTO_LIBRARY that it seems to be looking for is either /mingw64/lib/libcrypto.a or /mingw64/lib/libcrypto.dll.a.

What's really throwing me for a loop is that in the CMake error message, it says "found version 1.1.1b", so clearly it is able to find it. Anyone have suggestions on how to resolve this error?


Solution

  • Turns out, I needed to add -G "Unix Makefiles" to my cmake command. By default it was producing Visual Studio solutions/projects, which is not what you want in mingw, and by adding this flag it was able to find the openssl files.