linux无法编译libevent,一直报错,但是我有装openssl

linux无法编译libevent,一直报错,但是我有装openssl

这是 libevent 与 openssl 版本不兼容导致。

一般来说,它们的版本关系是这样的

libevent openssl
2.1.x 1.1
2.0.x 1.0
因此你有两个选择

使用 libevent 2.1.x 版本,这与你本机的 openssl 1.1 匹配,无需任何修改直接编译即可。
使用 libevent 2.0.x 版本,你需要安装 openssl 1.0 版本,然后在编译时指定链接版本。
下面针对第二种选择做详细说明,这种方法是通用的,适用于编译其他软件时出现版本不兼容问题。

首先安装 openssl 1.0 版本,注意需要头文件。你可以选择从源码安装,或使用操作系统的仓库下载安装。
这类安装包通常带有 “*-dev” 字样,比如 centos 发行版可能是这样的

yum install openssl-devel-1.0xxx
openssl 安装完成后,会有一个 pkgconfig/ 目录,实际路径取决于你上一步的操作,一般位于 /usr/lib 或 /usr/local/lib 下。
这里我们假设是 /usr/local/lib/openssl-1.0/pkgconfig/, 你需要将它设置成 PKG_CONFIG_PATH 的环境变量值,如

export PKG_CONFIG_PATH=/usr/local/lib/openssl-1.0/pkgconfig/
切换到 libevent 源码目录,把 openssl 头文件路径,及库文件路径加入 configure 配置变量,如

./configure CFLAGS=“ ( p k g − c o n f i g − − c f l a g s o p e n s s l ) " L D F L A G S = " (pkg-config --cflags openssl)" LDFLAGS=" (pkgconfigcflagsopenssl)"LDFLAGS="(pkg-config --libs openssl)”
清除原内容,并重新编译即可

make clean
make -j8

centos 安装libevent-2.1.12-stable.tar.gz
直接去官网找到目标
直接wget
如果失败,可以使用页面下载,然后上传到centos下
解压进入目录
直接
./configure
make
这样是不行的
sample/le_proxy-le-proxy.o: In function main': /root/libevent-2.1.12-stable/sample/le-proxy.c:283: undefined reference to TLS_method’
./.libs/libevent_openssl.so: undefined reference to BIO_meth_set_read' ./.libs/libevent_openssl.so: undefined reference to BIO_set_shutdown’
./.libs/libevent_openssl.so: undefined reference to BIO_get_data' ./.libs/libevent_openssl.so: undefined reference to BIO_meth_set_write’
./.libs/libevent_openssl.so: undefined reference to BIO_meth_set_ctrl' ./.libs/libevent_openssl.so: undefined reference to BIO_meth_set_create’
./.libs/libevent_openssl.so: undefined reference to BIO_meth_set_puts' ./.libs/libevent_openssl.so: undefined reference to BIO_get_shutdown’
./.libs/libevent_openssl.so: undefined reference to BIO_meth_new' ./.libs/libevent_openssl.so: undefined reference to BIO_set_init’
./.libs/libevent_openssl.so: undefined reference to BIO_get_init' ./.libs/libevent_openssl.so: undefined reference to BIO_meth_set_destroy’
./.libs/libevent_openssl.so: undefined reference to BIO_set_data' collect2: error: ld returned 1 exit status make[1]: *** [sample/le-proxy] Error 1 make[1]: Leaving directory /root/libevent-2.1.12-stable’

需要设置pkgconfig
先找到
find / -name pkgconfig |grep openssl
/usr/openssl/lib/pkgconfig
在设置
export PKG_CONFIG_PATH=/usr/openssl/lib/pkgconfig
./configure CFLAGS=“ ( p k g − c o n f i g − − c f l a g s o p e n s s l ) " L D F L A G S = " (pkg-config --cflags openssl)" LDFLAGS=" (pkgconfigcflagsopenssl)"LDFLAGS="(pkg-config --libs openssl)”
make -j4
make install

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值