一、问题描述
本人的工位电脑是 Mac系统 。我首先使用 brew
下载了 openssl
。之后在执行./configure --prefix=/usr/local
语句配置 libevent
的时候出现了如下报错:
configure: error: openssl is a must but can not be found. You should add the directory containing `openssl.pc' to the `PKG_CONFIG_PATH' environment variable,
or set `CFLAGS' and `LDFLAGS' directly for openssl, or use `--disable-openssl' to disable support for openssl encryption
二、问题分析
- 通过观察报错信息,我们可以看到问题在于 找不到
openssl
:configure: error: openssl is a must but can not be found. You should add the directory containing 'openssl.pc' to the 'PKG_CONFIG_PATH' environment variable, or set 'CFLAGS' and 'LDFLAGS' directly for openssl, or use '--disable-openssl' to disable support for openssl encryption
- 在这之后,报错信息给了我们两种解决方案,这里我们使用第一种:将包含
openssl.pc
的路径加入到环境变量中。
三、解决方案
写在前面
首先,下面的解决方案中的路径只代表我的电脑上的路径。大家需要根据 下方第1点 查看自己的路径。
其次,下方第3点 的环境变量可能要注意一下,我忘了我是用export设置的还是写入配置文件里了。如果按我写的方式还是报错,可以尝试查看 参考文献[3]和[1]。(呜呜呜,大半夜的孩子累傻了)
最后,请注意我安装的版本是 libevent-2.1.10,其他版本可能会有别的问题。
-
查看通过
brew
下载的openssl
的目录位置。brew list openssl
-
通过上一步我们会看到如下图所示的输出结果,在展示的所有目录中,
openssl.pc
位于.../lib/pkgconfig/
目录下。
对我来说是:/opt/homebrew/Cellar/openssl@3/3.3.0/lib/pkgconfig
-
写入环境变量
export PKG_CONFIG_PATH=/opt/homebrew/Cellar/openssl@3/3.3.0/lib/pkgconfig export CPPFLAGS=-I/opt/homebrew/Cellar/openssl@3/3.3.0/include export LDFLAGS=-L/opt/homebrew/Cellar/openssl@3/3.3.0/lib
-
建立映射:此处是因为
brew
默认的安装目录不是系统默认目录,可能会导致libevent
找不到,因此需要映射。brew link openssl --force ln -s /usr/local/opt/openssl/bin/openssl /usr/local/bin/openssl ln -s /opt/homebrew/Cellar/openssl@3/3.3.0/include/openssl /usr/local/include/openssl ln -s /opt/homebrew/Cellar/openssl@3/3.3.0/lib/libssl.a /usr/local/lib/libssl.a ln -s /opt/homebrew/Cellar/openssl@3/3.3.0/lib/libcrypto.a /usr/local/lib/libcrypto.a
-
之后可以正常安装
libevent
。注意这里我使用的版本是libevent-2.1.10
,其他版本可能有问题。./configure --prefix=/usr/local make sudo make install
参考文献
[1] github上关于cmake报错的一个回答,https://github.com/libevent/libevent/issues/360#issuecomment-279690784
[2] 记录关于libevent安装错误:configure: error: openssl is a must but can not be found. You should add the direct,CSDN,https://blog.csdn.net/cyllsy/article/details/120773774
[3] bufferevent_openssl.c:66:10: fatal error: ‘openssl/bio.h’ file not found #465,Github,https://github.com/libevent/libevent/issues/465