村建站什么部门,wordpress 虎嗅,网络营销试卷,个人简历模板下载word格式CentOS 7 安装Libevent库
libevent github地址#xff1a;https://github.com/libevent/libevent
步骤1#xff1a;首先#xff0c;你需要下载libevent的源代码。你可以从github或者源代码官方网站下载。并上传至/usr/local/source_code/ 步骤2#xff1a;下载完成后https://github.com/libevent/libevent
步骤1首先你需要下载libevent的源代码。你可以从github或者源代码官方网站下载。并上传至/usr/local/source_code/ 步骤2下载完成后需要将源代码解压可以使用以下命令
[rootlocalhost source_code]# tar -zxvf libevent-2.1.12-stable.tar.gz步骤3解压后切换到源代码目录
[rootlocalhost source_code]# cd libevent-2.1.12-stable步骤4生成cJSON动态/静态库执行如下指令
[rootlocalhost libevent-2.1.12-stable]# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking whether make supports the include directive... yes (GNU
******
[rootlocalhost libevent-2.1.12-stable]# makeGEN test/rpcgen-attemptedGEN include/event2/event-config.h
make all-am
make[1]: 进入目录“/usr/local/source_code/libevent-2.1.12-stable”CC sample/dns-example.oCC buffer.loCC bufferevent.loCC bufferevent_filter.lo
******
[rootlocalhost libevent-2.1.12-stable]# sudo make install
make install-am
make[1]: 进入目录“/usr/local/source_code/libevent-2.1.12-stable”
make[2]: 进入目录“/usr/local/source_code/libevent-2.1.12-stable”/usr/bin/mkdir -p /usr/local/bin/usr/bin/install -c event_rpcgen.py /usr/local/bin/usr/bin/mkdir -p /usr/local/lib
**** 遇到的问题及解决办法
编译执行./test_libevent,提示如下截图错误信息 产生原因在运行时程序无法找到libevent-2.1.so.7这个动态库因为该动态库在默认安装时存放的路径在/usr/local/lib下不在系统的默认查找路径内。
解决办法
[rootlocalhost libevent_demo]# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/openssl/lib
/usr/local/openssl/lib
[rootlocalhost libevent_demo]# echo /usr/local/lib /etc/ld.so.conf
[rootlocalhost libevent_demo]# sudo ldconfigLibevent 之Hello World
在/usr/local/source_code 新增 libevent_demo目录并新增 test_libevent.cpp文件文件内容如下
#include event2/event.h
#include iostream
#include string
void timer_cb(evutil_socket_t fd, short what, void *arg)
{auto str static_caststd::string *(arg);std::cout *str std::endl;
}
int main()
{std::string str Hello, World!;auto *base event_base_new();struct timeval five_seconds {1, 0};auto *ev event_new(base, -1, EV_TIMEOUT, timer_cb, (void *)str);event_add(ev, five_seconds);event_base_dispatch(base);event_free(ev);event_base_free(base);return 0;
}编译源码并执行
[rootlocalhost libevent_demo]# g test_libevent.cpp -o test_libevent -levent
[rootlocalhost libevent_demo]# ./test_libevent
Hello, World!Libevent 参考资料
libevent GitHub地址:https://github.com/libevent/libevent
libevent 编程指南: https://senlinzhan.github.io/2017/08/12/libevent/
libevent 深入浅出:https://aceld.gitbooks.io/libevent/content/