Ubuntu安装及测试Libevent

19.04测试通过

在官网下载最新的libevent安装包:

直接下载:
http://libevent.org/

  • 在当前目录下解压安装包:
    tar -zxvf libevent-xxxx.tzr.gz
    cd libevent-2.0.22-stable

  • 配置安装库的目标路径:
    ./configure --prefix=/usr
    (可能缺少gcc , 则安装gcc sudo apt install gcc
    checking for gcc… no
    checking for cc… no
    checking for cl.exe… no)

配置显示:
x@xx:~/Downloads/libevent-2.1.8-stable$ ./configure --prefix=/usr
checking for a BSD-compatible install… /usr/bin/install -c
checking whether build environment is sane… yes
checking for a thread-safe mkdir -p… /bin/mkdir -p
checking for gawk… no
checking for mawk… mawk
checking whether make sets $(MAKE)… yes
checking whether make supports nested variables… yes
checking whether make supports nested variables… (cached) yes
checking for style of include used by make… GNU
checking for gcc… gcc
checking whether the C compiler works… yes
checking for C compiler default output file name… a.out
checking for suffix of executables…
checking whether we are cross compiling… no
checking for suffix of object files… o
checking whether we are using the GNU C compiler… yes
checking whether gcc accepts -g… yes
checking for gcc option to accept ISO C89… none needed
checking whether gcc understands -c and -o together… yes
checking dependency style of gcc… gcc3
checking how to run the C preprocessor… gcc -E
checking for grep that handles long lines and -e… /bin/grep
checking for egrep… /bin/grep -E
checking for ANSI C header files… yes
checking for sys/types.h… yes
checking for sys/stat.h… yes
checking for stdlib.h… yes
checking for string.h… yes
checking for memory.h… yes
checking for strings.h… yes
checking for inttypes.h… yes
checking for stdint.h… yes

  • 编译安装libevent库:
    make
    sudo make install

  • 检测安装是否成功
    ls -al /usr/lib | grep libevent
    显示:

x@xx:~/Downloads/libevent-2.1.8-stable$ ls -al /usr/lib | grep libevent
lrwxrwxrwx   1 root root      21 Mar  4 22:49 libevent-2.1.so.6 -> libevent-2.1.so.6.0.2
-rwxr-xr-x   1 root root 1405672 Mar  4 22:49 libevent-2.1.so.6.0.2
-rw-r--r--   1 root root 2376080 Mar  4 22:49 libevent.a
lrwxrwxrwx   1 root root      26 Mar  4 22:49 libevent_core-2.1.so.6 -> libevent_core-2.1.so.6.0.2
-rwxr-xr-x   1 root root  916144 Mar  4 22:49 libevent_core-2.1.so.6.0.2
-rw-r--r--   1 root root 1577598 Mar  4 22:49 libevent_core.a
-rwxr-xr-x   1 root root     973 Mar  4 22:49 libevent_core.la
lrwxrwxrwx   1 root root      26 Mar  4 22:49 libevent_core.so -> libevent_core-2.1.so.6.0.2
lrwxrwxrwx   1 root root      27 Mar  4 22:49 libevent_extra-2.1.so.6 -> libevent_extra-2.1.so.6.0.2
-rwxr-xr-x   1 root root  517360 Mar  4 22:49 libevent_extra-2.1.so.6.0.2
-rw-r--r--   1 root root  798554 Mar  4 22:49 libevent_extra.a
-rwxr-xr-x   1 root root     980 Mar  4 22:49 libevent_extra.la
lrwxrwxrwx   1 root root      27 Mar  4 22:49 libevent_extra.so -> libevent_extra-2.1.so.6.0.2
-rwxr-xr-x   1 root root     938 Mar  4 22:49 libevent.la
lrwxrwxrwx   1 root root      30 Mar  4 22:49 libevent_pthreads-2.1.so.6 -> libevent_pthreads-2.1.so.6.0.2
-rwxr-xr-x   1 root root   26224 Mar  4 22:49 libevent_pthreads-2.1.so.6.0.2
-rw-r--r--   1 root root   26454 Mar  4 22:49 libevent_pthreads.a
-rwxr-xr-x   1 root root    1001 Mar  4 22:49 libevent_pthreads.la
lrwxrwxrwx   1 root root      30 Mar  4 22:49 libevent_pthreads.so -> libevent_pthreads-2.1.so.6.0.2
lrwxrwxrwx   1 root root      21 Mar  4 22:49 libevent.so -> libevent-2.1.so.6.0.2

测试libevent

可以直接到/usr/local/lib文件夹查看libevent,也可以通过命令直接显示:
  
  ls -al /usr/local/lib | grep libevent
  
  这里给出一个简单的测试用例test.cpp,代码如下:

#include <event.h>

#include <iostream>

struct event ev;
struct timeval tv;

using namespace std;

void time_cb(int fd, short event, void *argc)
{
    cout << "timer wakeup" << endl;
    event_add(&ev, &tv);
}

int main()
{
    struct event_base *base = event_init();

    tv.tv_sec = 10;
    tv.tv_usec = 0;
    evtimer_set(&ev, time_cb, NULL);
    event_add(&ev, &tv);
    event_base_dispatch(base);

    return 0;
}

然后进行编译执行,首先进入代码文件所在文件夹,编译:
g++ test.cpp -o test -levent

执行:
./test
执行结果如下则运行成功。

x@ubuntu:~/c$ ./test 
timer wakeup
timer wakeup
timer wakeup
timer wakeup
timer wakeup
timer wakeup
timer wakeup
timer wakeup
timer wakeup
timer wakeup
timer wakeup
timer wakeup
timer wakeup
timer wakeup
timer wakeup
timer wakeup
timer wakeup
timer wakeup
timer wakeup

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值