libevent在windows下使用步骤详解
来源:互联网 发布:2017年淘宝客最新玩法 编辑:程序博客网 时间:2024/06/05 18:50
Libevent官网:http://libevent.org/
windows 8下编译:
编译环境: windows 8 + VS2013
(1)解压libevent到D:\libevent\libevent-2.0.21-stable
(2)打开Microsoft visual studio 2010命令行工具
(3)修改以下三个文件,添加宏定义:
在以下3个文件开头添加“#define _WIN32_WINNT 0x0500”
libevent-2.0.21-stable\event_iocp.c
libevent-2.0.21-stable\evthread_win32.c
libevent-2.0.21-stable\listener.c
(4)使用VS命令提示工具编译:
cd/d D:\libevent\libevent-2.0.21-stable
nmake /f Makefile.nmake
(5)编译结果:
libevent_core.lib:All core event and buffer functionality. This library contains all the event_base, evbuffer, bufferevent, and utility functions.
libevent_extras.lib:This library defines protocol-specific functionality that you may or may not want for your application, including HTTP, DNS, and RPC.
libevent.lib:This library exists for historical reasons; it contains the contents of both libevent_core and libevent_extra. You shouldn’t use it; it may go away in a future version of Libevent.
(6)VS2013下使用lib在工程目录下分别创建include和lib目录。
把libevent解压目录下的所有.h复制到include目录。
把lievent解压目录下的include的event目录复制到include目录。
把libevent解压目录下的WIN32-Code下的event2mulu和tree.h复制到include目录。
把libevent解压目录下编译生成的3个.lib文件(libevent.lib、libevent_core.lib和libevent_extras.lib)复制到lib目录。
// LibeventTest.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <stdio.h> #include <iostream> // libevent头文件 #include <event.h>using namespace std;struct event ev; //事件struct timeval tv; //定时器/*事件处理函数,cb=callback*/void time_cb(int fd, short _event, void *argc){cout << "timer wakeup" << endl;event_add(&ev, &tv);/*重新添加定时器*/}int _tmain(int argc, _TCHAR* argv[]){WSADATA WSAData; /*初始化WINDOWS socket库*/WSAStartup(0x101, &WSAData);struct event_base *base = event_init();//初始化libevent库,相当于初始化一个Reactior,就可以注册事件了.tv.tv_sec = 3; //间隔tv.tv_usec = 0;evtimer_set(&ev, time_cb, NULL);//初始化关注的事件,并设置回调函数//等价于event_set(&ev, -1, 0, timer_cb, NULL);event_add(&ev, &tv);//注册事件 相当于调用Reactor::register_handler()函数注册事件event_base_dispatch(base);//进入消息循环和消息分发return 0;}
- libevent在windows下使用步骤详解
- libevent在windows下使用步骤详解
- libevent在windows下使用步骤详解
- [C++] 在windows下编译libevent 2.0
- libevent 在windows下的编译过程
- libevent 在windows下的编译过程
- Windows平台下libevent库的使用
- windows下编译及使用libevent
- windows下编译及使用libevent
- windows下编译及使用libevent
- windows下编译及使用libevent
- windows下编译及使用libevent
- VS2013 windows下编译及使用libevent
- windows下编译及使用libevent
- windows下编译及使用libevent
- 【云隐】windows下编译及使用libevent
- libevent在windows下面基础使用
- libevent使用步骤
- leetcode Remove Element
- RecycleView套用demo
- mysql 分表查询
- [c++ 温故知新]operator的使用方式
- 在Allegro中放置的元件显示不出来E- (SPMHA1-150): Symbol does not fit into the drawing ... reposition the symbol.
- libevent在windows下使用步骤详解
- Linux文件解压
- poj 1050 最大的子矩阵和
- 我的CS学习路线图
- 贝叶斯决策
- 接口开发
- leetcode Merge k Sorted Lists
- [Leetcode]Range Sum Query 2D - Immutable
- C 指针 数组