cmake - osx/mac - openssl brew
cmake - osx/mac - openssl brew
我正在使用以下 cmake 命令
# Search OpenSSL
find_package(PkgConfig REQUIRED)
pkg_search_module(OPENSSL REQUIRED openssl)
if( OPENSSL_FOUND )
include_directories(${OPENSSL_INCLUDE_DIRS})
message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
else()
# Error; with REQUIRED, pkg_search_module() will throw an error by it's own
endif()
它适用于 Linux 和 Mac,但在 Mac 上它使用 osx-shipped libssl - 这会引发大量弃用警告,例如'SSL_library_init' is deprecated: first deprecated in OS X 10.7"
使用 brew
我已经安装了更新的 - openssl-offical - libssl - 我如何告诉 cmake 中的 pkg_search_module
找到并使用 brew 版本?
好的,它开始工作了:)
brew upgrade openssl
brew link --force openssl
pkg-config --modversion openssl
#1.0.2
删除了 cmake 构建文件夹并重新运行 cmake ..
,上面的宏现在找到了 1.0.2 libssl :)
截至 2016 年底,这对我有用:
在CMakeLists.txt中:
find_package(openssl REQUIRED)
运行 像这样制作:
cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl .
乔纳森是对的。 MacOS 系统 open ssl 被认为是不安全的。这是对我有用的
通过brew安装或升级openssl
将这些添加到您的 CMakefile 中。您可以选择使用命令行参数或环境变量而不是硬编码
include_directories(在 /usr/local/Cellar/openssl/1.0.2p/包含之前)
find_library(OPENSSL_LIB
SSL
路径 /usr/local/Cellar/openssl/1.0.2p/lib
NO_DEFAULT_PATH)
find_library(CRYPTO_LIB
密码
路径 /usr/local/Cellar/openssl/1.0.2p/lib
NO_DEFAULT_PATH)
要查找 OpenSSL 目录,请使用以下命令:
brew list openssl
此问题的原因是 a bug in CMake -- 它没有正确使用备用 pkg-config
路径。
根据bug附带的合并请求,修复应该在cmake 3.17.0(2020年2月发布)中。
否则,使用。在您的 CMakeLists.txt
中对其进行硬编码会对使用 MacPorts 而不是 Homebrew 的人造成不利影响。
截至 2021 年底,这对我有用:
改为
cmake_minimum_required(VERSION 3.20.2)
和
find_package(OpenSSL REQUIRED)
如果你已经通过brew安装了指定版本的openssl,比如说openssl@1.1,那么你可以使用
brew info openssl@1.1
它会告诉您所有需要做的事情:
If you need to have openssl@1.1 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc
For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"
For pkg-config to find openssl@1.1 you may need to set:
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"
我正在使用以下 cmake 命令
# Search OpenSSL
find_package(PkgConfig REQUIRED)
pkg_search_module(OPENSSL REQUIRED openssl)
if( OPENSSL_FOUND )
include_directories(${OPENSSL_INCLUDE_DIRS})
message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
else()
# Error; with REQUIRED, pkg_search_module() will throw an error by it's own
endif()
它适用于 Linux 和 Mac,但在 Mac 上它使用 osx-shipped libssl - 这会引发大量弃用警告,例如'SSL_library_init' is deprecated: first deprecated in OS X 10.7"
使用 brew
我已经安装了更新的 - openssl-offical - libssl - 我如何告诉 cmake 中的 pkg_search_module
找到并使用 brew 版本?
好的,它开始工作了:)
brew upgrade openssl
brew link --force openssl
pkg-config --modversion openssl
#1.0.2
删除了 cmake 构建文件夹并重新运行 cmake ..
,上面的宏现在找到了 1.0.2 libssl :)
截至 2016 年底,这对我有用:
在CMakeLists.txt中:
find_package(openssl REQUIRED)
运行 像这样制作:
cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl .
乔纳森是对的。 MacOS 系统 open ssl 被认为是不安全的。这是对我有用的
通过brew安装或升级openssl
将这些添加到您的 CMakefile 中。您可以选择使用命令行参数或环境变量而不是硬编码
include_directories(在 /usr/local/Cellar/openssl/1.0.2p/包含之前) find_library(OPENSSL_LIB SSL 路径 /usr/local/Cellar/openssl/1.0.2p/lib NO_DEFAULT_PATH) find_library(CRYPTO_LIB 密码 路径 /usr/local/Cellar/openssl/1.0.2p/lib NO_DEFAULT_PATH)
要查找 OpenSSL 目录,请使用以下命令:
brew list openssl
此问题的原因是 a bug in CMake -- 它没有正确使用备用 pkg-config
路径。
根据bug附带的合并请求,修复应该在cmake 3.17.0(2020年2月发布)中。
否则,使用CMakeLists.txt
中对其进行硬编码会对使用 MacPorts 而不是 Homebrew 的人造成不利影响。
截至 2021 年底,这对我有用:
改为
cmake_minimum_required(VERSION 3.20.2)
和
find_package(OpenSSL REQUIRED)
如果你已经通过brew安装了指定版本的openssl,比如说openssl@1.1,那么你可以使用
brew info openssl@1.1
它会告诉您所有需要做的事情:
If you need to have openssl@1.1 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc
For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"
For pkg-config to find openssl@1.1 you may need to set:
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"