libevent官網:
windows 7下編譯:
編譯環境: windows 7 + vs2010
(1)解壓libevent到f:\libevent\libevent-2.0.21-stable
(2)開啟microsoft visual studio 2010命令列工具
(3)修改以下三個檔案,新增巨集定義:
在以下3個檔案開頭新增「#define _win32_winnt 0x0500」
libevent-2.0.21-stable\event_iocp.c
libevent-2.0.21-stable\evthread_win32.c
libevent-2.0.21-stable\listener.c
(4)使用vs命令提示工具編譯:
cd/d f:\libevent\libevent-2.0.21-stable
nmake /f makefile.nmake
(5)編譯結果:
libevent_core.lib:all core event and buffer functionality. this library contains all the event_base, evbuffer, bufferevent, and utility functions.
libevent.lib:this library exists for historical reasons; it contains the contents of both libevent_core and libevent_extra. you shouldn』t use it; it may go away in a future version of libevent.
(6)vs2010下使用lib
新建乙個vc++控制台專案:
環境配置:
專案下建乙個lib目錄,將上面三個lib檔案copy到該目錄下。
新建乙個include目錄,將f:\libevent\libevent-2.0.21-stable\include下的檔案和資料夾copy到該目錄下,f:\libevent\libevent-2.0.21-stable\win32-code下的檔案copy到該目錄下,2個event2目錄下的檔案可合併一起。
main**:
// libeventtest.cpp : 定義控制台應用程式的入口點。專案屬性設定://#include "stdafx.h"
#include #include #include #include #ifndef win32
#include # ifdef _xopen_source_extended
# include # endif
#include #endif
#include "event2/bufferevent.h"
#include "event2/buffer.h"
#include "event2/listener.h"
#include "event2/util.h"
#include "event2/event.h"
#include static const char message = "hello, world!\n";
static const int port = 9995;
static void conn_writecb(struct bufferevent *bev, void *user_data)
}static void conn_eventcb(struct bufferevent *bev, short events, void *user_data)
else if (events & bev_event_error)
* timeouts */
bufferevent_free(bev);
}static void signal_cb(evutil_socket_t sig, short events, void *user_data)
; printf("caught an interrupt signal; exiting cleanly in two seconds.\n");
event_base_loopexit(base, &delay);
}static void listener_cb(struct evconnlistener *listener, evutil_socket_t fd,
struct sockaddr *sa, int socklen, void *user_data)
bufferevent_setcb(bev, null, conn_writecb, conn_eventcb, null);
bufferevent_enable(bev, ev_write);
bufferevent_disable(bev, ev_read);
bufferevent_write(bev, message, strlen(message));
}int main(int argc, char **ar**)
memset(&sin, 0, sizeof(sin));
sin.sin_family = af_inet;
sin.sin_port = htons(port);
listener = evconnlistener_new_bind(base, listener_cb, (void *)base,
lev_opt_reuseable|lev_opt_close_on_free, -1,
(struct sockaddr*)&sin,
sizeof(sin));
if (!listener)
signal_event = evsignal_new(base, sigint, signal_cb, (void *)base);
if (!signal_event || event_add(signal_event, null)<0)
event_base_dispatch(base);
evconnlistener_free(listener);
event_free(signal_event);
event_base_free(base);
printf("done\n");
return 0;
}
vc++目錄:
包含目錄,新增:f:\projects\libeventtest\libeventtest\include;
庫目錄,新增:f:\projects\libeventtest\libeventtest\lib;
c/c++:
**生成-->執行庫:多執行緒除錯 (/mtd)(debug下),多執行緒 (/mt)(release下)
聯結器:
輸入:ws2_32.lib;wsock32.lib;libevent.lib;libevent_core.lib;libevent_extras.lib;
ws2_32.lib;wsock32.lib;是用來編譯windows網路相關的程式庫。
編譯,生成!
windows下編譯及使用libevent
libevent官網 windows 7下編譯 編譯環境 windows 7 vs2010 1 解壓libevent到f libevent libevent 2.0.21 stable 2 開啟microsoft visual studio 2010命令列工具 3 修改以下三個檔案,新增巨集定義 在...
windows環境下編譯zlib及使用
系統 win10 x64 ide vs2017 此時版本 zlib 1.2.11.zip 2.解壓 3.進入 contrib vstudio 子目錄,找到對應版本的vs開啟,然後編譯 備註 1 如果編譯過程中出現 fatal error lnk1281 無法生成 safeseh 映像 的錯誤,則將該...
windows下libevent的編譯及使用
之前簡單分析了libevent的原始碼,過了一段時間要用的時候發現完全忘記了。從頭記錄一下流程 1.編譯 修改以下三個檔案,新增巨集定義 在以下3個檔案開頭新增 define win32 winnt 0x0500 libevent 2.0.21 stable event iocp.c libeven...