libevent编译问题

官网下载:https://libevent.org/
直接地址:https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz

解压后编译,遇到如下问题,重装openssl也不行:

[root@localhost libevent-2.1.12-stable]# ./configure 
此处省略...
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
[root@localhost libevent-2.1.12-stable]# make
make: *** 没有指明目标并且找不到 makefile。 停止。
[root@localhost libevent-2.1.12-stable]# 

直接按照提示加了–disable-openssl就可以编译了

配置:

./configure --disable-openssl

如需要可以指定目录,则后续编译请指定库目录:
./configure -prefix=/usr/lib/libevent --disable-openssl

编译:

make && make install

查看安装与否:

ls -al /usr/lib | grep libevent

注意:如果编译时,发现找不到定义,请查看环境变量问题

测试 用例:

#include <iostream>

#include <event.h>
#include <time.h>

struct event ev;
struct timeval tv;

void timer_cb(int fd, short envent, void *arg)
{
        std::cout << "timer_cb" << std::endl;
        event_add(&ev, &tv);
}

int main()
{
        struct event_base *base = event_init();
        tv.tv_sec = 1;
        tv.tv_usec = 0;

        event_set(&ev, -1, 0, timer_cb, NULL);
        event_base_set(base, &ev);
        event_add(&ev, &tv);
        event_base_dispatch(base);
        return 0;
}

编译(将源码中的头文件拷贝到测试代码的目录):

[root@localhost test]# ls
a.out  compile.sh  include  libeventTest.cpp
[root@localhost test]# cat compile.sh
#!/bin/sh
g++ --static -I ./include libeventTest.cpp -levent
[root@localhost test]#

学习文档:https://www.bookstack.cn/read/libevent/450ef2232c710e15.md

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值