【libevent】configure: error: openssl is a must but can not be found. You should add the director……

一、问题描述

本人的工位电脑是 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

请添加图片描述

二、问题分析

  1. 通过观察报错信息,我们可以看到问题在于 找不到 opensslconfigure: 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
  2. 在这之后,报错信息给了我们两种解决方案,这里我们使用第一种:将包含 openssl.pc 的路径加入到环境变量中。

三、解决方案

写在前面
首先,下面的解决方案中的路径只代表我的电脑上的路径。大家需要根据 下方第1点 查看自己的路径。
其次,下方第3点 的环境变量可能要注意一下,我忘了我是用export设置的还是写入配置文件里了。如果按我写的方式还是报错,可以尝试查看 参考文献[3]和[1]。(呜呜呜,大半夜的孩子累傻了)
最后,请注意我安装的版本是 libevent-2.1.10,其他版本可能会有别的问题。

  1. 查看通过 brew 下载的 openssl 的目录位置。

    brew list openssl
    
  2. 通过上一步我们会看到如下图所示的输出结果,在展示的所有目录中,openssl.pc 位于 .../lib/pkgconfig/ 目录下。
    对我来说是:/opt/homebrew/Cellar/openssl@3/3.3.0/lib/pkgconfig
    请添加图片描述

  3. 写入环境变量

    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
    
  4. 建立映射:此处是因为 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
    
  5. 之后可以正常安装 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

  • 9
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

鱼儿听雨眠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值