gpt4 book ai didi

c++ - CMake在Brew上找不到OpenSSL

转载 作者:行者123 更新时间:2023-12-02 10:29:57 28 4
gpt4 key购买 nike

CMake无法为我找到OpenSSL。 Brew的OpenSSL位于/usr/local/Cellar/openssl/1.0.2s/。我在macOS Catalina上。
我的CMakeLists.txt看起来像这样:

[...]

set(OPENSSL_ROOT_DIR /usr/local/Cellar/openssl/1.0.2s)

find_package(OpenSSL REQUIRED)
target_include_directories(myapp PUBLIC ${OPENSSL_INCLUDE_DIR})
message(STATUS "OpenSSL: Version ${OPENSSL_VERSION}")
message(STATUS "OpenSSL: include dir at ${OPENSSL_INCLUDE_DIR}")
message(STATUS "OpenSSL: libraries at ${OPENSSL_LIBRARIES} ${OPENSSL_SSL_LIBRARIES}")

[...]

target_link_libraries(myapp
${CMAKE_DL_LIBS}
${OPENSSL_LIBRARIES}
${OPENSSL_SSL_LIBRARIES}
Qt5::Core
)
输出:
-- OpenSSL: Version 1.0.2s
-- OpenSSL: include dir at /usr/local/Cellar/openssl/1.0.2s/include
-- OpenSSL: libraries at /usr/lib/libssl.dylib;/usr/lib/libcrypto.dylib /usr/lib/libssl.dylib
因此,CMake找到了正确的包含目录,但是这些库是从我系统的OpenSSL安装中获取的?即使我根据 documentation指定了 OPENSSL_ROOT_DIR
为什么找不到这些文件?
/usr/local/Cellar/openssl/1.0.2s/lib/libcrypto.a
/usr/local/Cellar/openssl/1.0.2s/lib/pkgconfig/libssl.pc
/usr/local/Cellar/openssl/1.0.2s/lib/pkgconfig/libcrypto.pc
/usr/local/Cellar/openssl/1.0.2s/lib/libssl.dylib
/usr/local/Cellar/openssl/1.0.2s/lib/libcrypto.1.0.0.dylib
/usr/local/Cellar/openssl/1.0.2s/lib/libcrypto.dylib
/usr/local/Cellar/openssl/1.0.2s/lib/libssl.1.0.0.dylib
/usr/local/Cellar/openssl/1.0.2s/lib/libssl.a
如果我忽略了这一点,然后继续编译程序,则会得到:
ld: cannot link directly with /usr/lib/libcrypto.dylib for architecture x86_64
我尝试了 brew upgrade openssl的值(value)。
我从CLion运行CMake,并包含 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=/Users/me/Qt/5.9.7/clang_64

最佳答案

CMake缓存是问题。在CLion中,我可以通过转到Tools -> CMake -> Reset cache & reload project正确地重建/刷新CMake。之后,输出为:

-- OpenSSL: Version 1.0.2s
-- OpenSSL: include dir at /usr/local/Cellar/openssl/1.0.2s/include
-- OpenSSL: libraries at /usr/local/Cellar/openssl/1.0.2s/lib/libssl.dylib;/usr/local/Cellar/openssl/1.0.2s/lib/libcrypto.dylib /usr/local/Cellar/openssl/1.0.2s/lib/libssl.dylib
这似乎是正确的,并回答了我的问题。
另外,我必须做: brew switch openssl 1.0.2s才能正确编译。

关于c++ - CMake在Brew上找不到OpenSSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62604254/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com