zoukankan      html  css  js  c++  java
  • android ndk 编译 libevent

    1. 下载 libevent 2.1.8 版本

       https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz

    2. 先在 win10 上用 wsl ubuntu 编译 libevent

    3. 在 wsl 上,准备需要的编译环境

    sudo apt-get install automake
    sudo apt-get install autoconf
    sudo apt-get install libtool

    4. 在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 `.'

    5. ./configure

    6. make

    至此在 wsl ubuntu 上编译libevent已经完成了


    下面,就需要在android ndk 环境下编译

    1. 在windows上,下载最新版本的ndk

    2. 编写 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)

    3. 编译 Application.mk

    APP_STL      := c++_static
    APP_CPPFLAGS := -frtti -std=c++11
    APP_ABI      := armeabi-v7a arm64-v8a x86
    #APP_ABI     := armeabi-v7a

    4. 调用 ndk-build.cmd 就可以编译了


    编译过程中遇到的问题, 需要修改 ./include/event2/event-config.h 中的定义

    1. error: 'sys/sysctl.h' file not found

       注释定义  #define EVENT__HAVE_SYS_SYSCTL_H 1

    2. error: static declaration of 'arc4random_addrandom' follows non-static declaration

       增加定义  #define EVENT__HAVE_ARC4RANDOM 1

    3. error: use of undeclared identifier 'fd_mask'

       注释定义  #define EVENT__HAVE_FD_MASK 1

    4. error: 'sys/timerfd.h' file not found

       注释定义  #define EVENT__HAVE_SYS_TIMERFD_H 1

    5. error: use of undeclared identifier 'EPOLL_CLOEXEC'

       注释定义  #define EVENT__HAVE_EPOLL_CREATE1 1


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

  • 相关阅读:
    修改ubuntu DNS的步骤/wget url报错: unable to resolve host address的解决方法
    MySQL5.7 Replication主从复制配置教程
    总结一下安装linux系统经验-版本选择-安装ubuntu
    分布式与集群的联系与区别
    spring 后置处理器BeanFactoryPostProcessor和BeanPostProcessor的用法和区别
    mysql几种性能测试的工具使用
    mysql max_allowed_packet查询和修改
    mysql主从复制(超简单)
    10 个免费的网络监控工具(转)
    DOS批处理中%cd%和%~dp0的区别
  • 原文地址:https://www.cnblogs.com/russinovich/p/11809892.html
Copyright © 2011-2022 走看看