[文章作者:张宴 本文版本: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”三个文件,在文件开头分别加上一行:
#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\


  点击在新窗口中浏览此图片

  点击在新窗口中浏览此图片


  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图标制作工具下载






技术大类 » Windows相关 | 评论(53) | 引用(0) | 阅读(83841)
louis vuitton uk Email Homepage
2011-11-22 17:10
This louis vuitton uk for sale belongs to the sounding just what are termed as Louis Vuitton vintage best sellers, many other products and services for the reason that range appearing companies.You will easily notice the unfold zippers of this coach outlet store online. That is the decoration. There are some inside pockets for you as well. They are easy to match your clothes and to carry.Let us inspire your inner beauty with fine christian louboutin sale. Purse the elegance in bridal wedding. Enjoy the fashion.
armani watches Email Homepage
2011-11-23 10:12
If you are looking for armani Bags, our armani watches Handbags Canada outlet store is your first choice. We promise Original Packing and Best Discount,3-5 Workdays To Your Door!If you buy bags and purses of the latest new designs from the louis vuitton outlet now, you can enjoy special discounts. What else are you waiting for?After you choose the right kind of plants and the size pot for the plant.
昆明国旅 Email Homepage
2011-12-8 14:33
看不懂
云南旅游 Email Homepage
2011-12-8 14:35
无法解析的外部符号 __beginthread ,该符号在函数 _event_iocp_port_launch http://www.kmguolv.com/
wedding520 Email Homepage
2011-12-27 15:41
ワイドネックライン、'V'ネックやボートネックラインは、一般にキャップスリーブとドレスのために選ばれている。ボートスタイルのネックラインと幅広いネックラインのためには、オフショルダーのキャップスリーブを追加することができます。オフショルダーのウエディングドレスは、数年以来、結婚式の摩耗で人気のパターンになっても流行で、今日でもあります。カラードレス 格安.のこのスタイルで素敵に見える模様のオフショルダーの袖に行く同じシースのサテンからステッチ/オフショルダーのキャップスリーブの上に薄いと飾ったときに裾フレアのビットとシースのサテンのイブニングドレスとスパゲッティネックラインがすごい見えます。
hopocket Homepage
2012-2-4 10:37
学习了
asfs
2012-2-4 11:05
好文章,来支持下博主,谢谢!清洗剂http://www.dzhc188.com/
sandals on sale Email Homepage
2012-4-11 09:42
哦哦,很好,不过也很复杂啊
pumps on sale Email Homepage
2012-4-12 09:11
fear哎,不高兴啊今天
Abercrombie Email Homepage
2012-5-9 10:37
Néanmoins une option supplémentaire qui pourrait être éventuellement parmi les plus susceptibles de la chose importante le long de la création d'utilisation très sûre vers consommateur potentiel pourrait être la pour les Abercrombie magasins nets à charge même si dans l'intérieur du seul Royaume-Uni pour s'assurer que vous simplement de conserver l'essentiel en ce qui concerne les impôts qui vous autrement consacrer personnes se trouvant à devenir à l'achat dans le u. s. États. Etats pour le magasin nette.
Hogan Email Homepage
2012-5-10 17:46
Ci sono diversi motivi principali per cui si può sicuramente trovare sul proprio volere le soluzioni contabili che coinvolgono tutta Stansted, anche se alcune persone potrebbero uomini e donne, probabilmente si dovrà disporre di soluzioni contabili rispetto con la gente. Stai con me per scoprire di più su molti dei motivi per prendere in considerazione l'impiego contabili in tutta Hogan Stansted. Costruire un businessIf vi capita di essere in funzione, è abbastanza possibile che si può fare uso di soluzioni contabili. Non date per scontato tutte le società hanno abbastanza soldi per utilizzare a tempo pieno il personale fiscali, così utilizzando una conditi insieme con l'agenzia affidabile che coinvolge tutta commercialisti Stansted potrebbe rendere meno difficili problemi.
hogan280 Email
2012-5-10 18:01
Nazir Afzal, il pubblico ministero appena nominato capo nazionale per il Nord Ovest, che era responsabile per portare i responsabili in giudizio, ha detto al Guardian: "Non era la loro gara che li ha definiti, è stato il loro trattamento delle Hogan donne". Prima di aggiungere: "Non c'è nessuna comunità in cui le donne e le ragazze non sono vulnerabili agli attacchi sessuali e questo è un dato di fatto."
cxf0401
2012-6-11 10:34
Michael Kors handbags outlet Bundled in the assortment are white mink Michael Kors handbags sporting chain handles in gleaming silver and the chocolate viscose tote with rabbit trim. Welcome to our online sales shop, where you can always buy the most affordable price to a your favorite Michael Kors outlet.
cheapsunglasses Email Homepage
2012-6-21 09:17
额,菜鸟一个
fashion sunglasses Email Homepage
2012-6-29 09:49
I have read the post which is very useful for me. I like !!!thanks for sharing it. welcome to fashion zone www.vivilli.com
lirourou77 Email Homepage
2012-9-5 13:10
in a new mechanism of system to replace the old in medicine have medical mechanism, which is the cheap designer handbags      
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,
cheap north face Email Homepage
2012-10-27 15:10
reports that Indian companies are competing for talent by offering a wide array of benefits for prospective workers extended family! Some perks the article cited include no-interest loans for parents and siblings, free movie tickets and health club/swimming pool memberships. When a 20-something engineer got a job offer from Google, Microsoft reportedly offered him $250,000 to stay, He said no thanks,Offshoring is getting tougher as well, In its December issue, FastCompany well know Discount North Face with good reviews  reports that Indian companies are competing for talent by offering a wide array of benefits for prospective workers extended family! Some perks the article cited include no-interest loans for parents and siblings, free movie tickets and health club/swimming pool memberships.
Coach Email Homepage
2012-11-3 14:42
"The Coach Outletengines that will likely power the J-31 we do know a bit mor.Coach Outlet  Those engines were actually revealed at the Zhuhai showCoach Outlet in 2008," Fisher said referring to an annual China air show. He beCoach Outletlieves the new J-31 engine is undergoing preliminary
分页: 2/3 第一页 上页 1 2 3 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]