Linux之libevent的編譯&測試__Linux

來源:互聯網
上載者:User
1.下載
http://download.csdn.net/detail/sauphy/9314091


2. 編譯
./configure --prefix=/opt/libevent
make
make install


3. 開發編譯
gcc test_signal.c -o ok -I/opt/libevent/include -L/opt/libevent/lib -levent
./ok


3-1、串連出錯:
error while loading shared libraries: 
libevent-2.0.so.5: cannot open shared object file: No such file or directory
A1、
ln -s /opt/libevent/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5


4. 運行
./ok

Ctrl+C 運行(顯示兩個訊號)


===============================

#include <sys/types.h>#include <event2/event-config.h>#include <sys/stat.h>#ifndef WIN32#include <sys/queue.h>#include <unistd.h>#include <sys/time.h>#else#include <winsock2.h>#include <windows.h>#endif#include <signal.h>#include <fcntl.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <errno.h>#include <event.h>#ifdef _EVENT___func__#define __func__ _EVENT___func__#endifint called = 0;static voidsignal_cb(evutil_socket_t fd, short event, void *arg){struct event *signal = arg;printf("%s: got signal %d\n", __func__, EVENT_SIGNAL(signal));if (called >= 2)event_del(signal);called++;}intmain(int argc, char **argv){struct event signal_int;struct event_base* base;#ifdef WIN32WORD wVersionRequested;WSADATA wsaData;wVersionRequested = MAKEWORD(2, 2);(void) WSAStartup(wVersionRequested, &wsaData);#endif/* Initalize the event library */base = event_base_new();/* Initalize one event */event_assign(&signal_int, base, SIGINT, EV_SIGNAL|EV_PERSIST, signal_cb,    &signal_int);event_add(&signal_int, NULL);event_base_dispatch(base);event_base_free(base);return (0);}

================

CC       = gccCXX      = g++LD_FLAG  = -gLIBS     = -L/opt/libevent/lib -leventINCLUDES = -I/opt/libevent/includeTARGET = ok${TARGET}:        $(CC) main.c $(LD_FLAG) $(LIBS) $(INCLUDES) -o  $(TARGET) clean:        rm -rf *.o *~ $(TARGET)


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.