当前位置: 首页 > article >正文

android ndk 编译 libevent

android ndk 编译 libevent
Russinovich`s Blog 2022-10-19 原文
https://www.shuzhiduo.com/A/rV57oAKG5P/

  1. 下载 libevent 2.1.8 版本

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

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

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

sudo apt-get install automake

sudo apt-get install autoconf

sudo apt-get install libtool

  1. 在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 `.’

  1. ./configure

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

  1. 编译 Application.mk

APP_STL := c++_static

APP_CPPFLAGS := -frtti -std=c++11

APP_ABI := armeabi-v7a arm64-v8a x86

#APP_ABI := armeabi-v7a

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

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

  1. error: ‘sys/sysctl.h’ file not found

注释定义 #define EVENT__HAVE_SYS_SYSCTL_H 1

  1. error: static declaration of ‘arc4random_addrandom’ follows non-static declaration

增加定义 #define EVENT__HAVE_ARC4RANDOM 1

  1. error: use of undeclared identifier ‘fd_mask’

注释定义 #define EVENT__HAVE_FD_MASK 1

  1. error: ‘sys/timerfd.h’ file not found

注释定义 #define EVENT__HAVE_SYS_TIMERFD_H 1

  1. error: use of undeclared identifier ‘EPOLL_CLOEXEC’

注释定义 #define EVENT__HAVE_EPOLL_CREATE1 1

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


http://www.kler.cn/news/10551.html

相关文章:

  • setInterval 让它刚进页面时执行一次,然后根据设置的间隔时间执行;clearInterval清除setInterval。
  • webgl-根据鼠标点击而移动
  • linux对动态库的搜索知识梳理
  • 推荐 ChatGpt 平替介绍文章
  • TensorFlow 机器学习秘籍第二版:6~8
  • 常见网络协议汇总(一)
  • 前端手写综合考题
  • DS-NeRF代码
  • 【SpringMVC】SpringMVC注解式开发
  • ChatGPT实现用C语言写一个学生成绩管理系统
  • 阻塞/非阻塞、同步/异步、五种IO模型
  • SpringBoot基础配置
  • Spring相关概念
  • 2.28、共享内存(1)
  • springboot如何优雅的打印项目日志
  • 蹭ChatGPT热点有风险,昆仑万维蹭热点被发监管函
  • Vite打包后直接使用浏览器打开,显示空白问题
  • 题解,git的使用,MySQL与JDBC的使用(上)
  • NDK RTMP直播客户端二
  • Metasploit高级技术【第十章】
  • C++篇 ---- 命名空间namespace
  • 华为MatePad有什么好用的软件?
  • 用SSH登陆Centos系统时,命令行最前面显示“的提示符[root@www myapp]”是什么意思?
  • 【博学谷学习记录】超强总结,用心分享丨人工智能 AI项目 统计语言模型之HMM初步学习总结
  • 基于Python实现的深度学习技术在水文水质领域应用
  • Java多线程:定时器Timer
  • C++之入门之缺省参数函数重载引用
  • 【活动】高效学习方法分享
  • 「VS」Visual Studio 常用小技巧
  • 【C语言】迷宫问题