Conan CMake "Could NOT find OpenSSL" beheben
English
Deutsch
Problem:
Beim Erstellen des Conan-Pakets erscheint dieser CMake-Fehler:
cmake_findopenssl_error.txt
CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (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)
Call Stack (most recent call first):
/usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.16/Modules/FindOpenSSL.cmake:447 (find_package_handle_standard_args)
../_deps/curl-src/CMakeLists.txt:365 (find_package)obwohl die conanfile.py OpenSSL als Abhängigkeit deklariert:
conanfile.py
class MyPackageConan(ConanFile):
# ...
requires = ("openssl/1.1.1l", )Lösung
Sicherstellen, dass die CMakeLists.txt des Projekts diese Zeilen enthält:
CMakeLists_conan_setup.cmake
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()Normalerweise wird dies mit diesem Code gemacht, der automatisch von conan new generiert wird:
conan_source_replace.py
# This small hack might be useful to guarantee proper /MT /MD linkage
# in MSVC if the packaged project doesn't have variables to set it
# properly
tools.replace_in_file("hello/CMakeLists.txt", "PROJECT(HelloWorld)",
'''PROJECT(HelloWorld)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()''')in source() wie folgt:
conan_source.py
def source(self):
self.run("git clone https://github.com/conan-io/hello.git")
# This small hack might be useful to guarantee proper /MT /MD linkage
# in MSVC if the packaged project doesn't have variables to set it
# properly
tools.replace_in_file("hello/CMakeLists.txt", "PROJECT(HelloWorld)",
'''PROJECT(HelloWorld)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()''')Beachten, dass beide hello/CMakeLists.txt durch den korrekten Dateinamen ersetzt werden müssen (typischerweise einfach hello durch … ersetzen). Außerdem müssen beide Instanzen von PROJECT(HelloWorld) durch die tatsächliche Zeile aus der CMakeLists.txt ersetzt werden, damit der Replace-Befehl funktioniert.
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow