Libevent安装与简单使用

照常的废话

Libevent作为优秀的通用事件驱动库在世界上享有盛名。
能看到我这篇文章的同志们应该都很了解这个库是干什么的了,不多费口舌~
这一年一直做嵌入式,都快忘了自己的专业了~赶紧趁着假期补补课,开学现学现用一波。
网上的资料很多,简单整理了一下。

安装libevent

我的环境:
乌班图(16.04)衍生版本 Elementary OS

安装所需:

automake
Libevent 本体

对于automake就很简单,直接sudo apt install automake 安装即可。
(不装会出现 ./autogen.sh: 18: ./autogen.sh: aclocal: not found 这错误)

对于Libevent本体

git clone https://github.com/libevent/libevent.git
./autogen.sh
./configure
make
make install
make verify //这个可做可不做,我输入这个regression 会出一堆warning

之后就是编写简单的测试代码了。

测试Libevent

测试代码用的是

http://blog.csdn.net/q_l_s/article/details/51545373

博主文章里的代码。

扫描二维码关注公众号,回复: 747736 查看本文章

g++ ./libevent.cpp -o livevent -levent -L /usr/local/lib

编译通过。运行的时候发现错误:

error while loading shared libraries: libevent-2.2.so.1 : cannot open shared object file: No such file or directory

解决方法参考了以下文章:

http://blog.csdn.net/sg_mj/article/details/43866711 ——LibEvent的使用过程记录
https://www.cnblogs.com/bourneli/archive/2012/04/27/2474103.html ——gcc中的-Wl,rpath=选项

PS:第二个文章用法有一个小错误,参数不应该为rpath,而应该为 -rpath ~
正确命令如下

g++ ./libevent.cpp -o livevent -L/usr/local/lib -levent -Wl,-rpath=/usr/local/lib

运行./livevent ,问题解决。

猜你喜欢

转载自blog.csdn.net/sunhaobo1996/article/details/79338327