android ndk 编译 libevent
Russinovich`s Blog 2022-10-19 原文
https://www.shuzhiduo.com/A/rV57oAKG5P/
- 下载 libevent 2.1.8 版本
https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz
-
先在 win10 上用 wsl ubuntu 编译 libevent
-
在 wsl 上,准备需要的编译环境
sudo apt-get install automake
sudo apt-get install autoconf
sudo apt-get install libtool
- 在livevent目录下运行 autogen.sh
./autogen.sh
autoreconf: Entering directory `.’
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force -I m4
autoreconf: configure.ac: tracing
autoreconf: running: libtoolize --copy --force
libtoolize: putting auxiliary files in ‘.’.
libtoolize: copying file ‘./ltmain.sh’
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, ‘m4’.
libtoolize: copying file ‘m4/libtool.m4’
libtoolize: copying file ‘m4/ltoptions.m4’
libtoolize: copying file ‘m4/ltsugar.m4’
libtoolize: copying file ‘m4/ltversion.m4’
libtoolize: copying file ‘m4/lt~obsolete.m4’
autoreconf: running: /usr/bin/autoconf --force
autoreconf: running: /usr/bin/autoheader --force
autoreconf: running: automake --add-missing --copy --force-missing
configure.ac:25: installing ‘./compile’
configure.ac:13: installing ‘./missing’
Makefile.am: installing ‘./depcomp’
autoreconf: Leaving directory `.’
-
./configure
-
make
至此在 wsl ubuntu 上编译libevent已经完成了
下面,就需要在android ndk 环境下编译
-
在windows上,下载最新版本的ndk
-
编写 Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_ARM_MODE := arm
LOCAL_MODULE := libevent
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_CFLAGS += -pie -fPIE -static -fPIC
include $(BUILD_STATIC_LIBRARY)
- 编译 Application.mk
APP_STL := c++_static
APP_CPPFLAGS := -frtti -std=c++11
APP_ABI := armeabi-v7a arm64-v8a x86
#APP_ABI := armeabi-v7a
- 调用 ndk-build.cmd 就可以编译了
编译过程中遇到的问题, 需要修改 ./include/event2/event-config.h 中的定义
- error: ‘sys/sysctl.h’ file not found
注释定义 #define EVENT__HAVE_SYS_SYSCTL_H 1
- error: static declaration of ‘arc4random_addrandom’ follows non-static declaration
增加定义 #define EVENT__HAVE_ARC4RANDOM 1
- error: use of undeclared identifier ‘fd_mask’
注释定义 #define EVENT__HAVE_FD_MASK 1
- error: ‘sys/timerfd.h’ file not found
注释定义 #define EVENT__HAVE_SYS_TIMERFD_H 1
- error: use of undeclared identifier ‘EPOLL_CLOEXEC’
注释定义 #define EVENT__HAVE_EPOLL_CREATE1 1
基本上就对event-config.h中的一些配置做调整就可以在ndk环境当中编译了,非常简单!