首先在https://libevent.org/下載最新的Stable releases libevent-2.1.11-stable.tar.gz
編譯前的准備
解壓縮之后修改以下5個文件
在 event_iocp.c evthread_win32.c listener.c 中加入一個宏定義 #define _WIN32_WINNT 0x0500
修改 minheap-internal.h 其中有一個UINT32_MAX的宏定義不受支持 改成UINT_MAX
修改 Makefile.nmake 找到 CFLAGS=$(CFLAGS) /Ox /W3 /wd4996 /nologo /Zi 務必加上最后一個選項方便調試
開始編譯
打開 x86 Native Tools Command Prompt for VS 2019 切換到 libevent-2.1.11-stable 目錄下執行 nmake /f Makefile.nmake
會生成3個lib文件
libevent_core.lib:All core event and buffer functionality. This library contains all the event_base, evbuffer, bufferevent, and utility functions.
libevent_extras.lib:This library defines protocol-specific functionality that you may or may not want for your application, including HTTP, DNS, and RPC.
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.
不建議使用 libevent.lib
編譯完成后使用
在目錄下新生成了一個 WIN32-Code 把WIN32-Code\nmake目錄下的所有內容復制到 include中 即可開始使用
在測試工程中添加 include 包含目錄,鏈接依賴項中添加ws2_32.lib;wsock32.lib;libevent_core.lib
測試結果