android ndk 编译 libevent

北城余情 提交于 2019-12-03 22:57:32

  1. 下载 libevent 2.1.8 版本

  2. 先在win10上用wsl编译 libevent

  3. 在wsl上,准备需要的编译环境
    sudo apt-get install automake sudo apt-get install autoconf sudo apt-get install libtool
  4. 运行 autogen.sh
    ``` bash
    ./autogen.ch

    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.'
    ```
  5. ./configure
  6. make
    至此在wsl上编译 libevent已经完成
    ---
    下面就在android ndk 环境下编译
  7. 在windows上,准备最新版本的ndk
  8. 编写 Android.mk
    ``` 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_SRC_FILES := $(LIB_SRC)
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/compat
    LOCAL_CFLAGS += -pie -fPIE -static -fPIC
    include $(BUILD_STATIC_LIBRARY)
    ```
  9. 编译 Application.mk
    C APP_STL := c++_static APP_CPPFLAGS := -frtti -std=c++11 APP_ABI := armeabi-v7a arm64-v8a x86
  10. 调用 ndk-build.cmd 就可以编译了

    编译过程中遇到的问题

  11. error: 'sys/sysctl.h' file not found 注释 event-config.h 中的 #define EVENT__HAVE_SYS_SYSCTL_H 1
  12. error: static declaration of 'arc4random_addrandom' follows non-static declaration 增加定义 #define EVENT__HAVE_ARC4RANDOM 1
  13. error: use of undeclared identifier 'fd_mask' 注释掉定义 #define EVENT__HAVE_FD_MASK 1
  14. error: 'sys/timerfd.h' file not found 注释掉定义 #define EVENT__HAVE_SYS_TIMERFD_H 1
  15. error: use of undeclared identifier 'EPOLL_CLOEXEC' 注释掉定义 #define EVENT__HAVE_EPOLL_CREATE1 1

基本上就对event-config.h中的一些配置做调整就可以在ndk环境当中编译了,非常简单!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!