先在win10上用wsl编译 libevent
- 在wsl上,准备需要的编译环境
sudo apt-get install automake sudo apt-get install autoconf sudo apt-get install libtool
运行 autogen.sh
autoreconf: Entering directory
``` bash
./autogen.ch.' 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上编译 libevent已经完成
---
下面就在android ndk 环境下编译 - 在windows上,准备最新版本的ndk
编写 Android.mk
LOCAL_SRC_FILES := $(LIB_SRC)
``` C
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_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/compat
LOCAL_CFLAGS += -pie -fPIE -static -fPIC
include $(BUILD_STATIC_LIBRARY)
```- 编译 Application.mk
C APP_STL := c++_static APP_CPPFLAGS := -frtti -std=c++11 APP_ABI := armeabi-v7a arm64-v8a x86
调用 ndk-build.cmd 就可以编译了
编译过程中遇到的问题
- error: 'sys/sysctl.h' file not found 注释 event-config.h 中的 #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环境当中编译了,非常简单!