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

fbhdf
2026-7-28 16:25
This specific is a great article My spouse and i witnessed due to talk about the idea. It is definitely precisely what I want to to view expect throughout potential you can proceed pertaining to expressing a real exceptional article. spiderman thongs
se
2026-7-29 22:07
Genuinely reliable, wonderful, fact-filled data below. Your current blogposts Do not ever let down, knowning that surely holds true below also. Anyone often create a unique go through. Could you explain to I am just satisfied?: )#) Carry on the fantastic content. naughty lingerie for women
SEI
2026-7-29 22:07
Genuinely reliable, wonderful, fact-filled data below. Your current blogposts Do not ever let down, knowning that surely holds true below also. Anyone often create a unique go through. Could you explain to I am just satisfied?: )#) Carry on the fantastic content. naughty lingerie for women
RAZA
2026-8-4 16:26
this can be awesome plus meanful. this can be interesting site. Leading is rather handy element. you may have seriously made it simpler for many people who seem to take a look at site and give these folks usefull information and facts. 성인 피시방 허가
sd
2026-8-4 17:29
Maintain the fantastic perform, My partner and i examine handful of content with this internet site and also I do believe your net website will be genuine intriguing and contains received bags regarding great details. 성인 피시방 먹튀사이트
RAZA
2026-8-5 17:13
We notion it really is a good idea to publish could anyone was initially having issues searching for however , My organization is a bit of dubious just have always been allowed to insert leaders together with contact regarding at this point. 성인 피시방 수입
taha
2026-8-8 14:06
This particular is a superb publish We observed because of reveal this. It really is exactly what I needed to determine wish within long term you'll carry on with regard to discussing this type of superb publish. 성인 피시방 허가
as
2026-8-8 16:07
I read that Post and got it fine and informative. 성인 피시방 창업
asd
2026-8-9 20:32
Beneficial Write-up, My business is an enormous believer with placing reviews with web-sites to help allow blog site internet writers are aware that they’ve added in anything effective to help online! 하자진단
EAZA
2026-8-10 17:04
Please share more like that. 성인 피시방
raza
2026-8-12 19:44
Typical trips listed below are the ultimate way to many thanks to your energy, which usually is why Now i'm browsing your website each day, trying to find fresh, intriguing details. Several, thanks! 성인 피시방 매매
RAZA
2026-8-15 02:40
I am truly pleased to discover this website as well as do appreciate reading through helpful content articles submitted right here. The actual suggestions from the writer had been amazing, many thanks for that reveal. bandar slot gacor
seg
2026-8-15 18:54
Standard sessions allow me to share the simplest way to thanks a lot for ones hard work, which in turn is the reason why I am just traveling to the web page every day, seeking brand-new, exciting information. A lot of, cheers! 성인 피시방 팝니다
asd
2026-8-15 21:46
I simply believed it might be a concept to publish in case other people had been having issues studying however I'm just a little uncertain basically 'm permitted to place titles as well as handles upon right here. slot depo 5k
AS
2026-8-17 15:43
You can be permitted to content artists, however it is not connections, in the event they are simply endorsed and additionally relating to question. 성인 피시방 단속
dgsdgsdg
2026-8-22 18:51
You're permitted to publish titles, although not hyperlinks, unless of course they're authorized as well as upon subject. 성인 피시방 벌금
AAA
2026-8-24 16:59
Some times its a pain in the ass to read what people wrote but this website is real user genial ! . 바카라 커뮤니티
分页: 5/5
1 2 3 4 5
1 2 3 4 5
Windows 和 Linux 下生成以当前时间命名的文件
快速配置 Samba 将 Linux 目录映射为 Windows 驱动器,用于跨平台编程

2011-3-30 08:40 | by







