中国本科高等质量建设研究网站,网站建设理由,seo排名优化北京,中国装修公司排行榜ubuntu下载安装libevent libevent 官网上下载最新稳定版本#xff0c;然后拖到你的linux系统中#xff0c;解压。或者可是使用wget在线下载。本文下载的是最新版本#xff0c;其他版本同操作 tar xf libevent-2.1.12-stable.tar.gz 进入解压后的目录#xff0c;执行 ./con…ubuntu下载安装libevent libevent 官网上下载最新稳定版本然后拖到你的linux系统中解压。或者可是使用wget在线下载。本文下载的是最新版本其他版本同操作 tar xf libevent-2.1.12-stable.tar.gz 进入解压后的目录执行 ./configure 可能会出现报错内容如下 checking for library containing SSL_new... no
checking for library containing SSL_new... no
checking openssl/ssl.h usability... no
checking openssl/ssl.h presence... no
checking for openssl/ssl.h... no
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解决办法安装libssl-dev sudo apt install libssl-dev安装 make
sudo make install查看安装成功否 ls /usr/local/lib/libevent*若出现下面的文件则安装成功。 ls /usr/local/lib/libevent*
/usr/local/lib/libevent-2.1.so.7 /usr/local/lib/libevent_extra.la
/usr/local/lib/libevent-2.1.so.7.0.1 /usr/local/lib/libevent_extra.so
/usr/local/lib/libevent.a /usr/local/lib/libevent_openssl-2.1.so.7
/usr/local/lib/libevent.la /usr/local/lib/libevent_openssl-2.1.so.7.0.1
/usr/local/lib/libevent.so /usr/local/lib/libevent_openssl.a
/usr/local/lib/libevent_core-2.1.so.7 /usr/local/lib/libevent_openssl.la
/usr/local/lib/libevent_core-2.1.so.7.0.1 /usr/local/lib/libevent_openssl.so
/usr/local/lib/libevent_core.a /usr/local/lib/libevent_pthreads-2.1.so.7
/usr/local/lib/libevent_core.la /usr/local/lib/libevent_pthreads-2.1.so.7.0.1
/usr/local/lib/libevent_core.so /usr/local/lib/libevent_pthreads.a
/usr/local/lib/libevent_extra-2.1.so.7 /usr/local/lib/libevent_pthreads.la
/usr/local/lib/libevent_extra-2.1.so.7.0.1 /usr/local/lib/libevent_pthreads.so
/usr/local/lib/libevent_extra.a编译的时候加-levent选项 代码示例 // 信号事件
void signal_cb(int fd, short event, void *arg)
{printf(SIGINT is comming! if you wang exit process, please enter other signal\n);
}// 定时事件
void time_cb(int fd, short event, void *arg)
{printf(time out\n);exit(0);
}int main()
{struct event_base *base event_init(); // base为Libevent的一个实例,对base进行初始化// 创建信号事件struct event *signal_event evsignal_new(base, SIGINT, signal_cb, NULL);event_add(signal_event, NULL); // 将事件注册到Libevent中// 创建定时事件timeval tm{5}; // 定时时间5sstruct event *time_event evtimer_new(base, time_cb, NULL);event_add(time_event, tm); // 将事件注册到Libevent中// 执行事件循环,检测就绪事件event_base_dispatch(base);// 事件循环结束,释放资源event_free(signal_event);event_free(time_event);event_base_free(base);return 0;
}上述程序捕捉2号信号并设置捕捉超时时间5秒。