1.源码下载地址:
链接:https://pan.baidu.com/s/1fxotILo3oTMC65z4qFAh9Q 密码:oc31
2.库的编译与安装
解压文件,进入文件目录
编译的时候需要首先切换为管理员(root)账户,然后执行以下命令:
./configure
make
make install
编译好后,它是被放在了/usr/local/lib这个文件夹里面
3.设置系统 动态库 链接路径
在运行的时候需要连接动态库,由于默认的动态库搜寻范围没有/usr/local/lib
打开配置文件: /etc/ld.so.conf
在最后另起一行,加上/usr/local/lib,保存退出即可。
然后终端执行命令 ldconfig
这样动态库搜寻范围就有/usr/local/lib了,程序链接动态库时就能找到libev库了
有关于共享库PATH以及ld.so.conf的更详细介绍请看:http://www.cnblogs.com/nanqiang/p/7521325.html
4.官方例子
#include <stdio.h> #include <ev.h> ev_io stdin_watcher; ev_timer timeout_watcher; static void stdin_cb(EV_P_ ev_io *w, int revents) { puts("stdin ready"); ev_io_stop(EV_A_ w); ev_break(EV_A_ EVBREAK_ALL); } static void timeout_cb(EV_P_ ev_timer *w, int revnts) { puts("time out"); ev_break(EV_A_ EVBREAK_ONE); } int main(void) { struct ev_loop *loop = EV_DEFAULT; ev_io_init(&stdin_watcher, stdin_cb, 0, EV_READ); ev_io_start(loop, &stdin_watcher); ev_timer_init(&timeout_watcher, timeout_cb, 10, 0); ev_timer_start(loop, &timeout_watcher); ev_run(loop, 0); return 0; }
保存命名为server.c文件
编译:gcc -o server server.c -lev
运行:./server
结果:time out