Libevent学习-源码下载和交叉编译,示例代码运行

 

1. 官网

 

 

2. 交叉编译

    我的当前环境

 

 

mips平台交叉编译说明

先解压下载后的libevent源码压缩包
然后cd进入解压后的文件夹libevent-2.1.11-stable:

<1.
  ./configure --prefix=/home/lmw/open_lib/Libevent/LibEventStupHere --host=mips-linux-gnu CC=mips-linux-gnu-gcc CXX=mips-linux-gnu-g++

  #--prefix指定安装目录, --host指定将要运行的特定平台, CC、CXX分别指定C语言和C++语言的编译器

<2.
  make

<3.
  make install

 

嵌入式平台系统上所需的动态库

 

 

 

3. 编写示例代码,运行libevent应用程序

    我的当前环境

 

 

timer.c

#include <stdio.h>
#include <sys/types.h>
#include <event.h>
#include <event2/event-config.h>

struct event ev;
struct timeval tv;

void time_cb(int fd, short event, void* argc)
{
    printf("HI, Libevent on MIPS(X1000 soc)!   Timer func test OK \r\n");
    event_add(&ev, &tv);
}

int main(int argc, char* argv[])
{
    struct event_base *base = event_init();
    printf("----start----\n");

    tv.tv_sec = 0;
    tv.tv_usec = 1000*1000;
    evtimer_set(&ev, time_cb, NULL);

    event_base_set(base, &ev);

    event_add(&ev, &tv);

    event_base_dispatch(base);

    printf("----end----\n");

    return 0;
}

makefile:

.PHONY: justdoit


justdoit:
    @echo "hello ~@Libevent@~ "
    mips-linux-gnu-gcc timer.c -o timer_app -I/home/lmw/open_lib/Libevent/LibEventStupHere/include/ -L/home/lmw/open_lib/Libevent/LibEventStupHere/lib/ -levent

运行效果:

 

 

 

.

posted @ 2021-01-04 16:05  一匹夫  阅读(1075)  评论(0编辑  收藏  举报