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
运行效果:
.
/************* 社会的有色眼光是:博士生、研究生、本科生、车间工人; 重点大学高材生、普通院校、二流院校、野鸡大学; 年薪百万、五十万、五万; 这些都只是帽子,可以失败千百次,但我和社会都觉得,人只要成功一次,就能换一顶帽子,只是社会看不见你之前的失败的帽子。 当然,换帽子决不是最终目的,走好自己的路就行。 杭州.大话西游 *******/