[文章作者:张宴 本文版本:v1.0 最后修改:2011.03.30 转载请注明原文链接:http://blog.zyan.cc/libevent_windows/]
本文介绍了如何在 Windows 操作系统中,利用微软 Visual Studio 2005 编译生成 Libevent 2.0.10 静态链接库,并利用 Libevent 静态链接库,实现一个简单的 HTTP Web服务器程序:httpd.exe。
假设 Visual Studio 2005 的安装路径为“D:\Program Files\Microsoft Visual Studio 8\”,Libevent 2.0.10 解压后的路径为“D:\libevent-2.0.10-stable”。
一、编译生成 Libevent 2.0.10 静态链接库。
1、修改“D:\libevent-2.0.10-stable\event_iocp.c”、“D:\libevent-2.0.10-stable\evthread_win32.c”、“D:\libevent-2.0.10-stable\listener.c”三个文件,在文件开头分别加上一行:
2、鼠标点击Windows左下角的【开始】-【所有程序】,找到【Microsoft Visual Studio 2005】,执行下图中的脚本:

3、按照下图中的方法编译Libevent 2.0.10:

4、生成的“libevent.lib”、“libevent_core.lib”、“libevent_extras.lib”三个文件就是我们需要的 Libevent 静态链接库。

二、利用 Libevent 静态链接库,实现一个简单的 HTTP Web服务器程序
1、打开 Visual Studio 2005,新建一个项目

2、选择在“d:\test”目录内创建一个“Win32 控制台应用程序”

3、按照下图进行选择

4、创建完成项目后,会自动生成“d:\test\httpd\”目录,在该目录内创建一个“httpd.c”文件,内容如下:
5、回到 Visual Studio 2005,在左侧的【源文件】中选择【添加】-【现有项】,将上一步创建的“httpd.c”文件添加进来。

6、在【解决方案“httpd”】上点击鼠标右键,选择【属性】

7、将【配置】改为“Release”

8、将“D:\libevent-2.0.10-stable\include”整个目录复制到“D:\test\httpd\include”;将“D:\libevent-2.0.10-stable\WIN32-Code”目录内的“tree.h”文件和“event2”子目录,复制到“D:\test\httpd\include\”内;将“D:\libevent-2.0.10-stable\”目录内的所有“*.h”头文件复制到“D:\test\httpd\include\”内。可以在Windows左下角的【开始】-【运行】中输入“cmd”回车,在命令行窗口中执行以下命令,完成复制过程。


9、回到 Visual Studio 2005,在左侧菜单中【解决方案“httpd”】下面一行【httpd】上点击鼠标邮件,选择【属性】,对每项内容进行修改。下图中红框内的数据即为修改后的数据。




注:下图中,附加依赖项填写:
忽略特定库填写:

10、完成设置后,在【解决方案“httpd”】上点击鼠标右键,选择【生成解决方案】。如果是重新编译,可以选择【重新生成解决方案】。生成成功后,“d:\test\httpd\Release”目录内的“httpd.exe”即为生成的可执行文件。

11、双击“httpd.exe”运行后,打开浏览器,访问“http://127.0.0.1:8505/”,则可以看到以下信息:一个简单的 HTTP Web Server 输出的内容。

12、如果你觉得像DOS程序一样的“httpd.exe”可执行文件图标不好看、没有显示版本信息,那么,你可以按照下图步骤,添加ICO图标文件。


13、添加版本信息


14、大功告成,下面显示的是带有自定义图标、版本信息的“httpd.exe”可执行程序。

附1:编译好的 Libevent 2.0.10 静态链接库与 httpd 的 Visual Studio 2005 工程源代码下载
下载文件
附2:ICO图标制作工具下载
下载文件


本文介绍了如何在 Windows 操作系统中,利用微软 Visual Studio 2005 编译生成 Libevent 2.0.10 静态链接库,并利用 Libevent 静态链接库,实现一个简单的 HTTP Web服务器程序:httpd.exe。
假设 Visual Studio 2005 的安装路径为“D:\Program Files\Microsoft Visual Studio 8\”,Libevent 2.0.10 解压后的路径为“D:\libevent-2.0.10-stable”。
一、编译生成 Libevent 2.0.10 静态链接库。
1、修改“D:\libevent-2.0.10-stable\event_iocp.c”、“D:\libevent-2.0.10-stable\evthread_win32.c”、“D:\libevent-2.0.10-stable\listener.c”三个文件,在文件开头分别加上一行:
#define _WIN32_WINNT 0x0500
2、鼠标点击Windows左下角的【开始】-【所有程序】,找到【Microsoft Visual Studio 2005】,执行下图中的脚本:

3、按照下图中的方法编译Libevent 2.0.10:

4、生成的“libevent.lib”、“libevent_core.lib”、“libevent_extras.lib”三个文件就是我们需要的 Libevent 静态链接库。

二、利用 Libevent 静态链接库,实现一个简单的 HTTP Web服务器程序
1、打开 Visual Studio 2005,新建一个项目

2、选择在“d:\test”目录内创建一个“Win32 控制台应用程序”

3、按照下图进行选择

4、创建完成项目后,会自动生成“d:\test\httpd\”目录,在该目录内创建一个“httpd.c”文件,内容如下:
5、回到 Visual Studio 2005,在左侧的【源文件】中选择【添加】-【现有项】,将上一步创建的“httpd.c”文件添加进来。

6、在【解决方案“httpd”】上点击鼠标右键,选择【属性】

7、将【配置】改为“Release”

8、将“D:\libevent-2.0.10-stable\include”整个目录复制到“D:\test\httpd\include”;将“D:\libevent-2.0.10-stable\WIN32-Code”目录内的“tree.h”文件和“event2”子目录,复制到“D:\test\httpd\include\”内;将“D:\libevent-2.0.10-stable\”目录内的所有“*.h”头文件复制到“D:\test\httpd\include\”内。可以在Windows左下角的【开始】-【运行】中输入“cmd”回车,在命令行窗口中执行以下命令,完成复制过程。
mkdir D:\test\httpd\include\
xcopy /E /H /R D:\libevent-2.0.10-stable\include\* D:\test\httpd\include\
xcopy /E /H /R D:\libevent-2.0.10-stable\WIN32-Code\* D:\test\httpd\include\
xcopy /E /H /R D:\libevent-2.0.10-stable\*.h D:\test\httpd\include\
xcopy /E /H /R D:\libevent-2.0.10-stable\include\* D:\test\httpd\include\
xcopy /E /H /R D:\libevent-2.0.10-stable\WIN32-Code\* D:\test\httpd\include\
xcopy /E /H /R D:\libevent-2.0.10-stable\*.h D:\test\httpd\include\


9、回到 Visual Studio 2005,在左侧菜单中【解决方案“httpd”】下面一行【httpd】上点击鼠标邮件,选择【属性】,对每项内容进行修改。下图中红框内的数据即为修改后的数据。




注:下图中,附加依赖项填写:
ws2_32.lib wsock32.lib libevent.lib libevent_core.lib libevent_extras.lib
忽略特定库填写:
libc.lib;msvcrt.lib;libcd.lib;libcmtd.lib;msvcrtd.lib

10、完成设置后,在【解决方案“httpd”】上点击鼠标右键,选择【生成解决方案】。如果是重新编译,可以选择【重新生成解决方案】。生成成功后,“d:\test\httpd\Release”目录内的“httpd.exe”即为生成的可执行文件。

11、双击“httpd.exe”运行后,打开浏览器,访问“http://127.0.0.1:8505/”,则可以看到以下信息:一个简单的 HTTP Web Server 输出的内容。

12、如果你觉得像DOS程序一样的“httpd.exe”可执行文件图标不好看、没有显示版本信息,那么,你可以按照下图步骤,添加ICO图标文件。


13、添加版本信息


14、大功告成,下面显示的是带有自定义图标、版本信息的“httpd.exe”可执行程序。

附1:编译好的 Libevent 2.0.10 静态链接库与 httpd 的 Visual Studio 2005 工程源代码下载

附2:ICO图标制作工具下载



tiffanys
gucci uk
louis vuitton sac
burberry uk
ralph lauren uk
cattle nets", and click "online voting" found that, the original vote is paid, 1 yuan 1 ticket.
"If you have to vote online, by pay treasure, net silver or cell phone pays fee." HeXianSheng cheap designer clothes
said, let people will choose the doctors like this is a good thing, but if will pay it is stale, "so, mean who's money, who can election?"
【 operation 】 can buy tickets into batch quantity
discount designer handbags
According to HeXianSheng provide web site, reporter found "purple cattle nets", "popular activities" column in the article 1 is: ningxiang county "open the door the medical" advanced unit and "top ten doctors,