[文章作者:张宴 本文版本: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相关 | 评论(52) | 引用(0) | 阅读(82802)
ugg uk Email Homepage
2012-11-16 11:04
I live in Paris and i am very pleased to buy those lovely Australian, such expensive in France. My daughter is 12 years old ugg uk and she absolutely fall in love with her new boots!!! See you next time for other shoes delivered in the UK when I'm coming for work. This past Christmas my boyfriend and I wanted to buy each other practical gifts. I asked for Uggs so when I walk to classes my feet won't get soaked. I got the short chestnut from a local Track N Trail ugg sale. If you're buying Uggs get sized for them!I normally wear a size 9 of ugg outlet. I was fitted by an associate at the store and told I could wear a 7 or 8. I went with a 7 and wore them with socks for the first few weeks. The now are perfect. I also have large calves and they fit around them; the associate also suggested the Bailey Boots because they fit larger calves. Buy the Ugg spray too, it's $8 and well worth every cent.
noodlest Email
2012-12-21 14:01
我也遇到了这个问题(Libevent 2.0.21),不知道如何解决:
1、摘录“幸福慢点走”
2011-9-4 00:11
libevent-2.0.13-stable.tar.gz  用vs2003命令行编译,出了这个问题。拜托哪位给个解。
===========================
cd test
  nmake /F Makefile.nmake
  cl /I.. /I../WIN32-Code /I../include /I../compat /DWIN32 /DHAVE_CONFIG_H /DTINYTEST_LOCAL /Ox /W3 /wd4996 /nologo ..\libevent.lib ws2_32.lib shell32.lib advapi32.lib regress.obj regress_buffer.obj regress_http.obj regress_dns.obj  regress_testutils.obj  regress_rpc.obj regress.gen.obj  regress_et.obj regress_bufferevent.obj  regress_listener.obj regress_util.obj tinytest.obj  regress_main.obj regress_minheap.obj regress_iocp.obj  regress_thread.obj
regress_thread.obj : error LNK2019: 无法解析的外部符号 __beginthreadex ,该符号在函数 _thread_basic 中被引用
libevent.lib(event_iocp.obj) : error LNK2019: 无法解析的外部符号 __beginthread ,该符号在函数 _event_iocp_port_launch 中被引用
regress.exe : fatal error LNK1120: 2 个无法解析的外部命令

2、测试Httpd例子:
正在链接...
libevent.lib(event.obj) : error LNK2019: 无法解析的外部符号 _errno ,该符号在函数 _evthread_notify_base_default 中被引用
libevent.lib(log.obj) : error LNK2001: 无法解析的外部符号 _errno
libevent.lib(signal.obj) : error LNK2001: 无法解析的外部符号 _errno
Release/TestHttpd.exe : fatal error LNK1120: 1 个无法解析的外部命令

3、用下载的编译过的库:
正在链接...
libevent.lib(event.obj) : error LNK2019: 无法解析的外部符号 _errno ,该符号在函数 _evthread_notify_base_default 中被引用
libevent.lib(log.obj) : error LNK2001: 无法解析的外部符号 _errno
libevent.lib(signal.obj) : error LNK2001: 无法解析的外部符号 _errno
Release/TestSimple.exe : fatal error LNK1120: 1 个无法解析的外部命令
cnbtmovie Email Homepage
2013-3-13 10:39
好像没实际用处.
磨途歌 Email
2013-10-21 20:27
磨途歌学习了
Steven Email Homepage
2015-3-19 02:25
Thank you for this post Weight Loss Tea
steven Email Homepage
2015-3-20 05:33
Ann Email
2019-1-5 15:21
I would like to introduce you to a question-and-answer forum for programmers, with all the areas you can research such as windows, android, java, python, c... the website: https://stackanswers.net/search/python
토토사이트 Email Homepage
2023-5-22 16:45
Thank you for this informative article. I came across your blog while surfing the internet. If you can share more on topics like this in the future, it will help your friends a lot. Thanks for your great help. 토토사이트
토토사이트 추천 Email Homepage
2023-8-23 14:24
fantastic issues altogether, you simply received a brand new reader. 토토사이트 추천
메이저사이트 Email Homepage
2023-8-23 14:24
Oh my goodness! an incredible article dude. Thanks Nonetheless I am experiencing subject with ur rss . 메이저사이트
메이저놀이터 Email Homepage
2023-8-23 14:24
I am usually to blogging i genuinely appreciate your content. Your content has really peaks my interest. 메이저놀이터
메이저사이트 Email Homepage
2023-9-5 11:23
There is no doubt that your writing is one of the best article in kind of this subject, and has good points of each part. I hope many people can get great information from this study and here 메이저사이트
分页: 3/3 第一页 上页 1 2 3 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]