[文章作者:张宴 本文版本: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图标制作工具下载
下载文件 

asd
2026-8-25 18:50
I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. 예능 다시보기
AAA
2026-8-27 13:59
I believe that a simple and unassuming manner of life is best for everyone, best both for the body and the mind. 맞고 커뮤니티
sei
2026-8-29 21:39
My partner and i emerged onto your website although centering merely a bit submits. Great strategy for subsequent, I am bookmarking simultaneously catch the full goes up. funny panties
aaaa
2026-8-30 14:17
I dont leave a lot of comments on a lot of blogs each week but i felt i had to here. Do you need many drafts to make a post? 홀덤 커뮤니티
ASd
2026-8-30 15:31
A very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. 무료 스포츠 중계
asd
2026-8-30 19:51
That is great submit and also i spend time you just read this kind of submit. your blog will be great and you also have got excellent employees within your website. great revealing keep it up. UFA88S
raza
2026-8-30 20:51
That is great submit and also i spend time you just read this kind of submit. your blog will be great and you also have got excellent employees within your website. great revealing keep it up. UFA88S
AAA
2026-9-1 14:05
Thanks for your time so much for your impressive and amazing guide. I will not be reluctant to endorse your web sites to any individual who should receive direction on this problem. 코인 커뮤니티
as
2026-9-1 19:38
I read that Post and got it fine and informative. rtp slot pragmatic
Ali
2026-9-1 19:51
Amazing! Exactly what a watch opener this particular publish may be personally. Greatly valued, saved, We can’t await much more! 성인 피시방
asd
2026-9-3 22:06
I recently found many useful information in your website especially this blog page. Among the lots of comments on your articles. Thanks for sharing. live toto macau
asd
2026-9-7 19:40
Really special blog post, Thanks for your time designed for writing It education. Outstandingly drafted guide, if only every webmasters marketed the exact same a better standard of subject matter whilst you, cyberspace was obviously a better set. Satisfy continue the good work! buy social media follows
分页: 6/6
1 2 3 4 5 6
1 2 3 4 5 6
Windows 和 Linux 下生成以当前时间命名的文件
快速配置 Samba 将 Linux 目录映射为 Windows 驱动器,用于跨平台编程

2011-3-30 08:40 | by







