libevent_windows下使用方法—vs2005
2013-12-09 22:57
218 查看
1. 编译libevent-2.0.12-stable
打开vs中的dos工具,进入到libevent-2.0.12-stable所在目录,然后运行nmake /f Makefile.nmake.
编译完成后,libevent-2.0.12-stable目录中生成三个静态库libevent.lib libevent_core.lib libevent_extras.lib
2. 将库文件导入工程:
新建工程后,在工程中建一个include文件夹,将libevent-2.0.12-stable\include中的所有文件复制到工程中的include中,将libevent-2.0.12-stable\WIN32-Code中的“tree.h”和“event2”子目录复制到工程中新建的include中,最后将libevent-2.0.12-stable中的所有*.h头文件复制到工程中的include中。
也可以在【开始】-》【运行】-【cmd】dos中执行
xopy /E /H /R libevent-2.0.12-stable\include\* project\include\
xopy /E /H /R libevent-2.0.12-stable\WIN32-Code\* project\include\
xopy /E /H /R libevent-2.0.12-stable\*.h project\include\
(A) vs设置
1. 将include加入到工程中:
2. 设置运行时库:
3,选择语言c/c++,我觉得c++也应该可以
4.添加库到工程中:
5.添加依赖和忽略特定库:
附加依赖库为:ws2_32.lib wsock32.lib libevent.lib libevent_core.lib libevent_extras.lib
忽略特定库为:libc.lib;msvcrt.lib;libcd.lib;libcmtd.lib;msvcrtd.lib
最后,libevent搭建成功,可以些代码,测试代码为
//#include "test.h"
#include <stdio.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <event.h>
#include <evhttp.h>
void root_handler(struct evhttp_request *req, void *arg)
{
struct evbuffer *buf = evbuffer_new();
if(!buf){
puts("failed to create response buffer");
return;
}
evbuffer_add_printf(buf, "Hello: %s\n", evhttp_request_uri(req));
evhttp_send_reply(req, HTTP_OK, "OK", buf);
}
void generic_handler(struct evhttp_request *req, void *arg)
{
struct evbuffer *buf = evbuffer_new();
if(!buf){
puts("failed to create response buffer");
return;
}
evbuffer_add_printf(buf, "Requested: %s\n", evhttp_request_uri(req));
evhttp_send_reply(req, HTTP_OK, "OK", buf);
}
int main(int argc, wchar_t* argv[])
{
struct evhttp *httpd;
WSADATA wsaData;
DWORD Ret;
if ((Ret = WSAStartup(MAKEWORD(2, 2), &wsaData)) != 0) {
printf("WSAStartup failed with error %d\n", Ret);
return -1;
}
event_init();
httpd = evhttp_start("0.0.0.0", 8505);
if(!httpd){
return 1;
}
evhttp_set_cb(httpd, "/", root_handler, NULL);
evhttp_set_gencb(httpd, generic_handler, NULL);
printf("httpd server start OK!\n");
event_dispatch();
evhttp_free(httpd);
WSACleanup();
return 0;
}
打开vs中的dos工具,进入到libevent-2.0.12-stable所在目录,然后运行nmake /f Makefile.nmake.
编译完成后,libevent-2.0.12-stable目录中生成三个静态库libevent.lib libevent_core.lib libevent_extras.lib
2. 将库文件导入工程:
新建工程后,在工程中建一个include文件夹,将libevent-2.0.12-stable\include中的所有文件复制到工程中的include中,将libevent-2.0.12-stable\WIN32-Code中的“tree.h”和“event2”子目录复制到工程中新建的include中,最后将libevent-2.0.12-stable中的所有*.h头文件复制到工程中的include中。
也可以在【开始】-》【运行】-【cmd】dos中执行
xopy /E /H /R libevent-2.0.12-stable\include\* project\include\
xopy /E /H /R libevent-2.0.12-stable\WIN32-Code\* project\include\
xopy /E /H /R libevent-2.0.12-stable\*.h project\include\
(A) vs设置
1. 将include加入到工程中:
2. 设置运行时库:
3,选择语言c/c++,我觉得c++也应该可以
4.添加库到工程中:
5.添加依赖和忽略特定库:
附加依赖库为:ws2_32.lib wsock32.lib libevent.lib libevent_core.lib libevent_extras.lib
忽略特定库为:libc.lib;msvcrt.lib;libcd.lib;libcmtd.lib;msvcrtd.lib
最后,libevent搭建成功,可以些代码,测试代码为
//#include "test.h"
#include <stdio.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <event.h>
#include <evhttp.h>
void root_handler(struct evhttp_request *req, void *arg)
{
struct evbuffer *buf = evbuffer_new();
if(!buf){
puts("failed to create response buffer");
return;
}
evbuffer_add_printf(buf, "Hello: %s\n", evhttp_request_uri(req));
evhttp_send_reply(req, HTTP_OK, "OK", buf);
}
void generic_handler(struct evhttp_request *req, void *arg)
{
struct evbuffer *buf = evbuffer_new();
if(!buf){
puts("failed to create response buffer");
return;
}
evbuffer_add_printf(buf, "Requested: %s\n", evhttp_request_uri(req));
evhttp_send_reply(req, HTTP_OK, "OK", buf);
}
int main(int argc, wchar_t* argv[])
{
struct evhttp *httpd;
WSADATA wsaData;
DWORD Ret;
if ((Ret = WSAStartup(MAKEWORD(2, 2), &wsaData)) != 0) {
printf("WSAStartup failed with error %d\n", Ret);
return -1;
}
event_init();
httpd = evhttp_start("0.0.0.0", 8505);
if(!httpd){
return 1;
}
evhttp_set_cb(httpd, "/", root_handler, NULL);
evhttp_set_gencb(httpd, generic_handler, NULL);
printf("httpd server start OK!\n");
event_dispatch();
evhttp_free(httpd);
WSACleanup();
return 0;
}
相关文章推荐
- windows ffmpeg mingw编译流程及vs中的使用方法(vs2005及其以上可用)
- windows下使用vs2005编译libevent 2.0.21
- 使用windows自带ntp客户端进行时间同步的方法
- SelectDirectory使用方法以及EnableTaskWindows
- 【转】如何在Windows+VS2005使用最新静态libcurl 7.35.0获取网页数据,支持HTTPS
- eclipse下使用cygwin的方法(Windows下用eclipse玩gcc/g++和gdb)
- windows下的cmd命令与shell使用方法
- windows下Python版本切换使用方法
- windows下xcopy命令的使用方法详解
- Windows下Nginx的安装及使用方法入门
- api doc windows 安装方法及使用
- windows下如何使用thrift,及编译执行的全过程。boost库的使用,libevent 库的使用
- Qt使用Windows蓝牙API搜索蓝牙设备并建立串口服务的方法
- linux虚拟机与windows文件共享的设置与软件使用方法
- Windows下使用wxPython的pycrust交互shell方法。运行pywrap命令
- Windows下,Netbeans使用C++的配置方法
- 在Windows中提高内存使用效能的几种好方法
- windows下Qt编译Qtxlsx库和qtxlsx库的使用方法
- Linux--14:ubuntu12.04 vi不能正常使用、右上角出现红杠提醒更新出问题、网速比相同条件下windows下慢 解决方法
- Java简单方法批量修改Windows文件夹下的文件名(简单IO使用)