libevent for android
1. 准备工作
1.1 原材料
1.2 编译环境
ubuntu-12.04
ndk-r9d
2. 编译步骤
下载解压缩libevent文件
wget http://sourceforge.net/projects/levent/files/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gz
tar -zxf libevent-2.0.22-stable.tar.gz
创建一个event-config.h文件
cd libevent-2.0.22-stable/
mkdir -p ARM-Code/event2/
vim ARM-Code/event2/event-config.h
编辑event-config.h
#ifndef _EVENT2_EVENT_CONFIG_H_ #define _EVENT2_EVENT_CONFIG_H_
#define _EVENT_HAVE_SA_FAMILY_T 1 #define _EVENT_HAVE_SYS_SOCKET_H 1 #define _EVENT_HAVE_NETINET_IN_H 1 #define _EVENT_HAVE_SYS_TIME_H 1 #define _EVENT_HAVE_STDARG_H 1 #define _EVENT_HAVE_UNISTD_H 1 #define _EVENT_HAVE_NETINET_IN6_H 1 #define ARC4RANDOM_NOADDRANDOM 1 #define _EVENT_HAVE_STRLCPY 1 #define _EVENT_HAVE_STRSEP 1 #define _EVENT_HAVE_NETDB_H 1 #define _EVENT_HAVE_STRTOK_R 1 #define _EVENT_HAVE_FCNTL_H 1 #define _EVENT_HAVE_GETTIMEOFDAY 1 #define _EVENT_HAVE_INTTYPES_H 1 #define _EVENT_HAVE_MEMORY_H 1 #define _EVENT_HAVE_PUTENV 1 #define _EVENT_HAVE_SIGNAL 1 #define _EVENT_HAVE_STDARG_H 1 #define _EVENT_HAVE_STDDEF_H 1 #define _EVENT_HAVE_STDINT_H 1 #define _EVENT_HAVE_STDLIB_H 1 #define _EVENT_HAVE_STRINGS_H 1 #define _EVENT_HAVE_STRING_H 1 #define _EVENT_HAVE_STRTOLL 1 #define _EVENT_HAVE_STRUCT_IN6_ADDR 1 #define _EVENT_HAVE_STRUCT_IN6_ADDR_S6_ADDR16 1 #define _EVENT_HAVE_STRUCT_IN6_ADDR_S6_ADDR32 1 #define _EVENT_HAVE_STRUCT_SOCKADDR_IN6 1 #define _EVENT_HAVE_STRUCT_SOCKADDR_STORAGE 1 #define _EVENT_HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1 #define _EVENT_HAVE_SYS_PARAM_H 1 #define _EVENT_HAVE_SYS_STAT_H 1 #define _EVENT_HAVE_SYS_TIME_H 1 #define _EVENT_HAVE_SYS_TYPES_H 1 #define _EVENT_HAVE_TIMERCLEAR 1 #define _EVENT_HAVE_TIMERCMP 1 #define _EVENT_HAVE_TIMERISSET 1 #define _EVENT_HAVE_UINT16_T 1 #define _EVENT_HAVE_UINT32_T 1 #define _EVENT_HAVE_UINT64_T 1 #define _EVENT_HAVE_UINT8_T 1 #define _EVENT_HAVE_UINTPTR_T 1 #define _EVENT_HAVE_UMASK 1 #define _EVENT_HAVE_UNISTD_H 1 #define _EVENT_LT_OBJDIR ".libs/" #define _EVENT_NUMERIC_VERSION 0x02001500 #define _EVENT_PACKAGE "libevent" #define _EVENT_PACKAGE_BUGREPORT "" #define _EVENT_PACKAGE_NAME "" #define _EVENT_PACKAGE_STRING "" #define _EVENT_PACKAGE_TARNAME "" #define _EVENT_PACKAGE_URL "" #define _EVENT_PACKAGE_VERSION "" #define _EVENT_SIZEOF_INT 4 #define _EVENT_SIZEOF_LONG 4 #define _EVENT_SIZEOF_LONG_LONG 8 #define _EVENT_SIZEOF_SHORT 2 #define _EVENT_SIZEOF_SIZE_T 4 #define _EVENT_SIZEOF_VOID_P 4 #define _EVENT_STDC_HEADERS 1 #define _EVENT_TIME_WITH_SYS_TIME 1 #define _EVENT_VERSION "2.0.21-stable" #ifndef _EVENT___cplusplus #endif #define _EVENT_socklen_t unsigned int
#endif /* event2/event-config.h */
创建Android.mk文件
vim Android.mk
编写Android.mk文件
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_ARM_MODE := arm
LOCAL_MODULE := eventcore
LIB_SRC := \
event.c \
evthread.c \
buffer.c \
bufferevent.c \
bufferevent_filter.c \
bufferevent_pair.c \
listener.c \
bufferevent_ratelim.c \
evmap.c \
log.c \
evutil.c \
evutil_rand.c \
select.c \
poll.c \
epoll.c \
signal.c \
event_tagging.c \
http.c \
evdns.c \
evrpc.c \
bufferevent_sock.c
LOCAL_SRC_FILES := $(LIB_SRC)
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/include \
$(LOCAL_PATH)/compat \
$(LOCAL_PATH)/ARM-Code
include $(BUILD_SHARED_LIBRARY)
创建ndk项目文件
mkdir jni
vim jni/Android.mk
vim jni/Application.mk
编辑jni/Android.mk文件
include $(CLEAR_VARS)
include $(APP_PROJECT_PATH)/Android.mk
编辑jni/Application.mk
APP_PROJECT_PATH := $(call my-dir)/../ APP_STL:=gnustl_static # 根据自己的需要修改 APP_ABI := armeabi armeabi-v7a APP_PLATFORM := android-8
最后ndk-build就可以了
ndk-build
博客不在线,有问题直接联系QQ: 783713515
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。