首页libevent › windows下编译及使用libevent

windows下编译及使用libevent

Libevent官网:http://libevent.org/
windows下编译:
编译环境: 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_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.

(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代码:

项目属性设置:
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网络相关的程序库。

编译,生成!

发表评论