0. 前言

我使用的版本是libevent-2.0.21-stable。高级的应用还是得看官网文档http://www.wangafu.net/~nickm/libevent-2.0/doxygen/html/

1. 功能总结

libevent的核心作用是实现消息循环、消息队列管理与回调,可用来监听文件(socket也算文件)属性变化、超时、锁状态变化,其中超时可以用作Timer。
额外的功能是作为HTTP的server或client。

2. 编译

2.1 Linux版编译

在目录下
./configure && make
即可在./.lib/下得到5个.a静态库。 不确定是否在此之前我已安装好各种依赖库所以没遇到任何障碍。

liuhx@uc ~/Downloads/libevent-2.0.21-stable/.libs $ ll *.a
-rw-r--r-- 1 liuhx liuhx 2309114 Feb 17 13:38 libevent.a
-rw-r--r-- 1 liuhx liuhx 1431730 Feb 17 13:38 libevent_core.a
-rw-r--r-- 1 liuhx liuhx  877456 Feb 17 13:38 libevent_extra.a
-rw-r--r-- 1 liuhx liuhx  195868 Feb 17 13:38 libevent_openssl.a
-rw-r--r-- 1 liuhx liuhx   21998 Feb 17 13:38 libevent_pthreads.a

查看Makefile文件的内容,可得知4个静态库对应的源文件:

CORE_SRC = event.c evthread.c buffer.c \
	bufferevent.c bufferevent_sock.c bufferevent_filter.c \
	bufferevent_pair.c listener.c bufferevent_ratelim.c \
	evmap.c	log.c evutil.c evutil_rand.c strlcpy.c $(SYS_SRC)
EXTRA_SRC = event_tagging.c http.c evdns.c evrpc.c
libevent_pthreads_la_SOURCES = evthread_pthread.c
libevent_openssl_la_SOURCES = bufferevent_openssl.c

即libevent_core.a里是核心功能,其中$(SYS_SRC)在各个平台会不同,linux下是select.c、poll.c、epoll.c、signal.c等,windows下是win32select.c evthread_win32.c等,不一一列举了。libevent_extra.a里包含http、dns等功能。另外两个libevent_*.a就见名知意了。而libevent.a是libevent_core.a和libevent_extra.a的集合。

2.2 Windows版编译

可以用VS的Command Prompt(开始菜单->Visual Studio 2013->Visual Studio Tools->VS2013 x64 Native Tools Command Prompt,VS和CPU版本应对应到你所用的)在libevent目录下
nmake Makefile.nmake
就能得到

2015/02/26  10:40           336,040 libevent_extras.lib
2015/02/26  10:40           789,110 libevent.lib
2015/02/26  10:40           453,366 libevent_core.lib

3个静态库文件。

不过一般会习惯做成VS工程。所以新建一个VS静态库工程,对着Makefile.nmake的内容添加源文件、引用目录、预编译命令就行了。vcproj的部分内容如下:

<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\buffer.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\bufferevent.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\bufferevent_async.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\bufferevent_filter.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\bufferevent_pair.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\bufferevent_ratelim.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\bufferevent_sock.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\buffer_iocp.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\evdns.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\event.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\event_iocp.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\event_tagging.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\evmap.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\evrpc.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\evthread.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\evthread_win32.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\evutil.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\evutil_rand.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\http.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\listener.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\log.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\signal.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\strlcpy.c" />
<ClCompile Include="..\..\..\third_party\libevent-2.0.21-stable\win32select.c" />

windows平台在链接时需要加入ws2_32.lib和wsock32.lib

2.3 Android版编译

若是能看懂linux和windows的Makefile,那是很容易写好Android.mk的。但在此之前需要生成好android版的config.h和event-config.h。

目录下运行(ndk版本随意,请替换成对应的路径):

SYSROOT=~/Applications/android-ndk-r8e/platforms/android-8/arch-arm
./configure --host=arm-linux-androideabi CC=~/Applications/android-ndk-r8e/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc CFLAGS=--sysroot=$SYSROOT

这样就会生成好config.h了。然后再
make
过程中会调用sed修改好event-config.h。顺利的话会生成四个.a

liuhx@uc ~/Downloads/libevent-2.0.21-stable/.libs $ ll *.a
-rw-r--r-- 1 liuhx liuhx 455082 Feb 26 14:59 libevent.a
-rw-r--r-- 1 liuhx liuhx 267398 Feb 26 14:59 libevent_core.a
-rw-r--r-- 1 liuhx liuhx 187756 Feb 26 14:59 libevent_extra.a
-rw-r--r-- 1 liuhx liuhx   4014 Feb 26 14:59 libevent_pthreads.a

因为没有编译OpenSSL,所以不会有libevent_openssl.a。

前面的过程会弄好config.h和event-config.h,其中event-config.h是对应android版本的配置,是必须的,不然编不过,所以无法一上来就用Android.mk。过了make这一步才行,也就是要保留修改过的event-config.h来使用下面的Android.mk

LOCAL_PATH := $(call my-dir)/..
include $(CLEAR_VARS)
LOCAL_MODULE := libevent

LOCAL_SRC_FILES := \
    event.c \
    evutil.c \
    epoll.c \
    log.c \
    poll.c \
    select.c \
    signal.c \
    http.c \
    buffer.c \
    evthread.c \
    evmap.c \
    bufferevent.c \
    listener.c \
    evutil_rand.c \
    bufferevent_sock.c \
    bufferevent_filter.c \
    bufferevent_pair.c \
    strlcpy.c \
    event_tagging.c \
    evrpc.c \
    bufferevent_ratelim.c \
    evdns.c \
    evthread_pthread.c

LOCAL_C_INCLUDES := \
	$(LOCAL_PATH) \
    $(LOCAL_PATH)/include \
    $(LOCAL_PATH)/compat

LOCAL_CFLAGS := -DHAVE_CONFIG_H

include $(BUILD_SHARED_LIBRARY)

注意最后一行在集成到app时应该把BUILD_SHARED_LIBRARY应该替换成BUILD_STATIC_LIBRARY,这里仅为了编译。

转载请注明出处:http://blog.csdn.net/hursing

libevent2笔记(linux、windows、android的编译)的更多相关文章

  1. windows android studio 编译Jni动态库

    项目需要,折腾了半天搞定windows android studio环境编译Jni动态库,现记录下来. 准备安装环境: 1. android studio 下载地址是http://www.androi ...

  2. Windows、Linux、Android常用软件分享

    Windows.Linux.Android常用软件分享 前言 本来没准备写这篇博客,一是没时间,还有其他很多优先级更高的事情要做.二是写这种博客对我自己来说没什么的帮助,以前我就想好了不写教程类,使用 ...

  3. 在Mac/Linux/Windows上编译corefx遇到的问题及解决方法

    这两天尝试在Mac/Linux/Windows三大平台上编译.NET跨平台三驾马车(coreclr/corefx/dnx)之一的corefx(.NET Core Framework),结果三个平台的编 ...

  4. 使用android ndk编译x86 so在linux下使用的问题

    一直以为android ndk编译x86 so库可以在linxu下运行,结果我试了几次都行不通.后来想了一下,android ndk编译的库应该只能在android设备或模拟器上运行才有效,后来改用 ...

  5. 【转】android程序编译过程

    现在很多人想对Android工程的编译和打包进行自动化,比如建立每日构建系统.自动生成发布文件等等.这些都需要我们对Android工程的编译和打包有一个深入的理解,至少要知道它的每一步都做了什么,需要 ...

  6. 转 谈谈android反编译和防止反编译的方法

    谈谈android反编译和防止反编译的方法   android基于java的,而java反编译工具很强悍,所以对正常apk应用程序基本上可以做到100%反编译还原. 因此开发人员如果不准备开源自己的项 ...

  7. golang安装卸载 linux+windows+raspberryPI 平台

    参考  https://golang.org/doc/install 自ECUG2013洗脑回来,就渴望早点接触Go 听着许式伟和谢孟军的演讲 发现go的网络库的确很强大,高负载利器,语言的一些精简导 ...

  8. H3 android 系统编译

    http://bbs.ickey.cn/group-topic-id-57981.html [Orange Pi PC试用体验]11编译android源码笔记 编译android和编译linux有点类 ...

  9. 工欲善其事,必先利其器 软件工具开发关键词 protractor自动化测试工具 RegexBuddy正则 CodeSmith,LightSwitch:代码生成 CheatEngine:玩游戏修改内存值必备神器 ApkIDE:Android反编译工具 Reflector:反编译dll动态链接库

    工欲善其事,必先利其器 本文版权归翟士丹(Stan Zhai)和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利. 原文地址:http ...

随机推荐

  1. 利用Django和装饰器做一个简单的修改密码页面

    view视图代码: from django.shortcuts import render,redirect from django.http import HttpResponse from PIL ...

  2. 【xsy1144】选物品 主席树

    题目大意:$N$ 件物品摆成一排,给每个物品定义两个属性 $A$ 和$ B$,两件物品的 差异度 定义为它们两种属性的差的绝对值中较大的一个.如果要求出一些物品的差异度,我们先定义一个 理想物品,使它 ...

  3. (转)Linux 文件目录特殊权限设定(SUID,SGID,SBIT)

    原文:https://blog.csdn.net/leshami/article/details/77184029 Linux文件及目录的权限设定,除了我们孰知的读写执行(rwx)之外,还有一些特殊的 ...

  4. (转)IBM AIX系统为rootvg实现镜像

    IBM AIX系统为rootvg实现镜像 AIX系统安装的时候,没有选择安装镜像,因此在系统安装完成后,出于安全方面的考虑,决定为rootvg创建镜像. 工具/原料 AIX rootvg lspv c ...

  5. Python的不定长参数研究

     通过观察程序和运行结果我们发现,传参时将1传给了a,将2传给了b,将3,4,5传给了*args,将m=6,n=7,p=8传给了**kwargs.为什么是这样传参呢?*args和**kwargs又是什 ...

  6. Spring Boot 项目发布到 Tomcat 服务器

    第 1 步:将这个 Spring Boot 项目的打包方式设置为 war.<packaging>war</packaging> SpringBoot 默认有内嵌的 tomcat ...

  7. MySQL 5.7.21版本sql_mode=only_full_group_by问题

      用到GROUP BY 语句查询时com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #2 of SELECT ...

  8. 【数组】kSum问题

    一.2Sum 思路1: 首先对数组排序.不过由于最后返回两个数字的索引,所以需要事先对数据进行备份.然后采用2个指针l和r,分别从左端和右端向中间运动:当l和r位置的两个数字之和小于目标数字targe ...

  9. SPSS学习系列之SPSS Text Analytics是什么?

    不多说,直接上干货! IBM® SPSS® Text Analytics 是一个IBM® SPSS® Modeler 完全集成内插式插件,它采用了先进语言技术和Natural Language Pro ...

  10. Ubuntu14.04安装之后的一些配置

    不多说,直接上干货! 主要分为 一.root用户的开启和vim编辑器的安装 二.ssh的安装 三.静态ip的设置 四.中英切换文环境切换 一.root用户的开启和vim编辑器的安装 Ubuntu在默认 ...