從網上下載下傳解壓後,放在libev目錄下為例

./configure --prefix=$HOME/libev/usr/local
make
make install
安裝好後:
test.c為另加入的,用來測試
test.c如下
// a single header file is required
#include <ev.h>
// for puts
#include <stdio.h>
// every watcher type has its own typedef'd struct
// with the name ev_TYPE
ev_io stdin_watcher;
ev_timer timeout_watcher;
// all watcher callbacks have a similar signature
// this callback is called when data is readable on stdin
static void stdin_cb(EV_P_ ev_io *w, int revents) {
puts("stdin ready");
// for one-shot events, one must manually stop the watcher
// with its corresponding stop function.
ev_io_stop(EV_A_ w);
// this causes all nested ev_run's to stop iterating
ev_break(EV_A_ EVBREAK_ALL);
}
// another callback, this time for a time-out
static void timeout_cb(EV_P_ ev_timer *w, int revents) {
puts("timeout");
// this causes the innermost ev_run to stop iterating
ev_break(EV_A_ EVBREAK_ONE);
}
int main(void) {
// use the default event loop unless you have special needs
struct ev_loop *loop = EV_DEFAULT;
// initialise an io watcher, then start it
// this one will watch for stdin to become readable
ev_io_init(&stdin_watcher, stdin_cb, /*STDIN_FILENO*/ 0, EV_READ);
ev_io_start(loop, &stdin_watcher);
// initialise a timer watcher, then start it
// simple non-repeating 5.5 second timeout
ev_timer_init(&timeout_watcher, timeout_cb, 5.5, 0.);
ev_timer_start(loop, &timeout_watcher);
// now wait for events to arrive
ev_run(loop, 0);
// break was called, so exit
return 0;
}
編譯、連結
gcc test.c -o test -I usr/local/include/ -L usr/local/lib/ -lev
執行
./test
如果5.5s内stdin沒有輸入,則列印timeout,否則列印stdin ready
一般編譯項目的步驟是:
./configure
make
make install
這個configure檔案當中存放的是shell腳本。
configure檔案
利用這個configure的腳本來檢視你的linux的運作環境,然後生成一個Makefile檔案
比如他檢查某個核心函數可不可用的時候,他就會先寫一個test.c 然後通過cat指令追加到這個test.c檔案當中。然後編譯運作,看看gcc是否報錯。如果不報錯說明該系統支援該核心函數。
進而将你的configure的情況重定向到config.log日志檔案當中。這裡面包含configure的結果,以及你configure時遇到的問題和你曾經的configure指令行曆史記錄
autotools包括
automake, autoconf
以及其他一些工具,
automake
用于生成
Makefile
的模闆
Makefile.in
,
autoconf
用于生成
configure
檔案。
+---------+
| |
| |
Makefile.am +----> | automake| +-------> Makefile.in +-----+
| | |
| | |
| | |
+---------+ |
|
+---------+ |
| | |
| | v
configure.ac +----> | autoconf| +-------> configure +------+-----> Makefile
| |
| |
| |
+---------+
用到./configure --prefix進行指定安裝
如果不指定prefix,則可執行檔案預設放在/usr/local/bin,庫檔案預設放在/usr/local/lib,配置檔案預設放在/usr/local/etc。其它的資源檔案放在/usr /local/share
編譯、連結gcc test.c -o test -I usr/local/include/ -L usr/local/lib/ -lev 使用了環境變量