c++ - CMake 在 Brew 上找不到 OpenSSL
问题描述
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 中获取的?即使我按照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
了它的价值。
我从 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
. 在此之后,输出为:
-- 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
正确编译。
推荐阅读
- html - 有没有办法阻止我的 :active 按钮在 ::before/::after 上显示父级的悬停效果?
- jquery - 如何使用 JQuery empty() 方法更改 Modal 中的消息?
- html - 我是否需要在自定义单选按钮上使用 ARIA 角色属性才能符合可访问性指南?
- html - 为移动网站设置不同的高度/宽度
- c# - EF-Migration:忽略模型的部分重叠有界上下文
- python - Python 描述递归生成器调用/生成堆栈
- c# - 使用 Regex 开头的 Guid 字段过滤 mongodb 文档
- google-chrome-extension - chrome.PageAction.hide(tabId) 没有按预期工作
- if-statement - If then 语句使用两个不同的日期范围
- java - 从 Ant 运行 JUnit 时如何配置测试超时?