libcurl移植到android
一、总体概览
C库:libcurl 3.7
目标平台:android
编译平台:ubuntu 12
编译工具:ndk r7 or later
二、已知方法
1. 官网上给了两种方法,第一种方法是使用android源代码来一块编译,原文如下:
Method using the static makefile:
see the build notes in the packages/Android/Android.mk file.
Android.mk如下:
# Google Android makefile for curl and libcurl
#
# This file can be used when building curl using the full Android source
# release or the NDK. Most users do not want or need to do this; please
# instead read the Android section in docs/INSTALL for alternate
# methods.
#
# Place the curl source (including this makefile) into external/curl/ in the
# Android source tree. Then build them with 'make curl' or just 'make libcurl'
# from the Android root. Tested with Android versions 1.5, 2.1-2.3
#
# Note: you must first create a curl_config.h file by running configure in the
# Android environment. The only way I've found to do this is tricky. Perform a
# normal Android build with libcurl in the source tree, providing the target
# "showcommands" to make. The build will eventually fail (because curl_config.h
# doesn't exist yet), but the compiler commands used to build curl will be
# shown. Now, from the external/curl/ directory, run curl's normal configure
# command with flags that match what Android itself uses. This will mean
# putting the compiler directory into the PATH, putting the -I, -isystem and
# -D options into CPPFLAGS, putting the -W, -m, -f, -O and -nostdlib options
# into CFLAGS, and putting the -Wl, -L and -l options into LIBS, along with the
# path to the files libgcc.a, crtbegin_dynamic.o, and ccrtend_android.o.
# Remember that the paths must be absolute since you will not be running
# configure from the same directory as the Android make. The normal
# cross-compiler options must also be set. Note that the -c, -o, -MD and
# similar flags must not be set.
#
# To see all the LIBS options, you'll need to do the "showcommands" trick on an
# executable that's already buildable and watch what flags Android uses to link
# it (dhcpcd is a good choice to watch). You'll also want to add -L options to
# LIBS that point to the out/.../obj/lib/ and out/.../obj/system/lib/
# directories so that additional libraries can be found and used by curl.
#
# The end result will be a configure command that looks something like this
# (the environment variable A is set to the Android root path which makes the
# command shorter):
#
# A=`realpath ../..` && \
# PATH="$A/prebuilt/linux-x86/toolchain/arm-eabi-X/bin:$PATH" \
# ./configure --host=arm-linux CC=arm-eabi-gcc \
# CPPFLAGS="-I $A/system/core/include ..." \
# CFLAGS="-nostdlib -fno-exceptions -Wno-multichar ..." \
# LIBS="$A/prebuilt/linux-x86/toolchain/arm-eabi-X/lib/gcc/arm-eabi/X\
# /interwork/libgcc.a ..."
#
# Finally, copy the file COPYING to NOTICE so that the curl license gets put
# into the right place (but see the note about this below).
3. 第二中方法使用 android ndk的脚本自己定制一套工具链,方便配置变量
Method using a configure cross-compile (tested with Android NDK r7c, r8):
prepare the toolchain of the Android NDK for standalone use; this can be done by invoking the script:
./build/tools/make-standalone-toolchain.sh
which creates a usual cross-compile toolchain. Lets assume that you put this toolchain below /opt then invoke configure with something like:
export PATH=/opt/arm-linux-androideabi-4.4.3/bin:$PATH
./configure --host=arm-linux-androideabi [more configure options]
make
三、自己方法
第一种方法需要用到android源代码,很不方便;第二种需要配置很多configure参数才能保证make成功。我的方法是结合了以上两种方法,用./configure得到curl_config.h等文件,然后使用ndk-build来编译Android.mk,而不是直接用make.
1. 搭建NDK环境:
1.1 下载NDK
官网下载页:http://developer.android.com/tools/sdk/ndk/index.html下载下来后,解压缩
注:下载符合你操作系统位数的ndk;还有就是下载ndk32的,因为android的64位支持没多久,大部分还都是32位的;版本越新越好,新版本会修复很多编译器bug,支持更多的语言特性。
1.2 配置NDK环境参数
打开 ~/.bashrc文件:
export NDK_HOME=~/Android /android-ndk-r8
export PATH=$PATH:$NDK_HOME
export PATH=$PATH:$NDK_HOME/toolchains/arm-linux-androideabi-4.6/prebuilt/linux/bin
测试一下
ndk-build –v
注1:修改环境变量的方法有三种,但是以上这种关机后不会失效:
比如要把/etc/apache/bin目录添加到PATH中
- #PATH=$PATH:/etc/apache/bin
使用这种方法,每当登出PATH就会恢复
2. #vi /etc/profile
在适当位置添加PATH=$PATH:/etc/apache/bin
这种方法最好,除非你强制手动修改PATH的值,否则将不会被改变
3. #vi ~/.bash_profile
修改PATH行,把/etc/apache/bin添加进去
这种方法是针对用户起作用的
注2:ndk-build使用有两种方法
- cd ~/android-ndk-r9/samples/hello-jni/jni
ndk-build
2. $NDK_HOME/ndk-build -C ~/android-ndk-r9/samples/hello-jni/jni
用 -C 指出工程目录路径
2. 配置和编译libcurl
2.1 下载源代码http://curl.haxx.se/download.html,解压
2.2 命令行进入curl目录后,执行
./configure –host=arm-linux-androideabi
注:记住host一定是工具链前缀
2.3 把package/android/Android.mk修改一下,去掉后边的可执行文件相关的语句,我们只要生成静态库就行了。然后把package/android改为package/jni
注:文件结构必须是jni/Android.mk,否则ndk-build找不到。
2.4 命令行进入package,执行ndk-build,大功告成。
libcurl移植到android的更多相关文章
- Cocos2D-X2.2.3学习笔记9(处理重力感应事件,移植到Android加入两次返回退出游戏效果)
这节我们来学习Cocos2d-x的最后一节.怎样处理重力感应事件.移植到Android后加入再按一次返回键退出游戏等.我这里用的Android.IOS不会也没设备呃 效果图不好弄,由于是要移植到真机上 ...
- Cocos移植到Android的一些问题-中文乱码问题
Android平台版本和设备碎片化很严重,因此从Win32平台移植到Android平台会有很多问题,下面是我们归纳的从Win32平台移植到Android平台遇到的一些问题.在Android平台中文乱码 ...
- 将Unity3D游戏移植到Android平台上
将Unity3D游戏移植到Android平台是一件很容易的事情,只需要在File->Build Settings中选择Android平台,然后点击Switch Platform并Build出ap ...
- iperf linux版本移植到android (使用工具链方式不是使用Android.mk)
由于很多程序是用makefile编译linux应用程序的,如果移植到android就要重新写Android.mk,对于不熟悉这个的人来说,特别麻烦,所以这里介绍只修改makefile就能移植到andr ...
- Windows下将ImageMagick移植到Android平台
Windows下将ImageMagick移植到Android平台 原文链接 http://www.pedant.cn/2014/06/18/imagemagick-ported-android/ I ...
- React Native移植原生Android
(一)前言 之前已经写过了有关React Native移植原生Android项目的文章,不过因为RN版本更新的原因吧,跟着以前的文章可能会出现一些问题,对于初学者来讲还是会有很多疑难的困惑的,而且官方 ...
- ffmpeg 移植到 android 并使用
同步更新至个人blog:http://dxjia.cn/2015/07/ffmpeg-porting-to-android/ 空闲做了个小应用,从视频里截图,然后再将截图拼接为一个gif动画: 起初使 ...
- 基于Cocos2d-x-1.0.1的飞机大战游戏迁移到Cocos2d-x-3.0版本,并移植到Android平台成功运行
一.版本迁移中的问题 1.游戏元素Sprite.Label.Action等等的创建函数名都改为create. 2.函数的回调callfunc_selectorcallfuncN_selectorcal ...
- libxml移植到android
libxml是C语言写的xml解析库,是我们开发可移植程序的首选,下面讲述将其移植到android的步骤 1.下载已经配置好的源代码包android_libxml2.rar http://pan.ba ...
随机推荐
- AngularJS学习之MVC模式
AngularJS是谷歌开发维护的前端MVC框架,克服了HTML在构建应用上的不足,从而降低了开发的成本. 在学习AngularJS之前,有必要和之前学过的jQuery进行对比.jQuery是java ...
- Python Pygame(5)绘制基本图形
最近很火一些简单图形构成的小游戏,这里介绍一些绘制图形的函数. 1.绘制矩形 rect(Surface,color,Rect,width=0) 第一个参数指定矩形绘制到哪个Surface对象上 第二个 ...
- 《我是一只IT小小鸟》 读书笔记
<我是一只IT小小鸟>讲述了IT人员的成长经历,邀请了许多名IT行业的职员,学生,研究生写了自己的亲身经历和人生感悟,以书中可以看到我国IT行业的快速进步,以及看到IT员在这条道路上的坎坷 ...
- ansible的介绍和一些基本模块介绍
必须保证ansible工作站与各个node实现无密码ssh登入 ①:192.168.1.100 - 在你本地的工作站或服务器上安装 Ansible. ②:文件服务器1到代理服务器3 - 使用 19 ...
- 复利计算器Junit单元测试
一.测试场景 测试模块 测试输入 预期结果 运行结果 bug跟踪 复利计算 (本金,利率,年限,次数) 终值 测试运算结果 (100,5,3,1) 115.76 115.76 测试输入负数 ...
- Java容器深入浅出之Collection与Iterator接口
Java中用于保存对象的容器,除了数组,就是Collection和Map接口下的容器实现类了,包括用于迭代容器中对象的Iterator接口,构成了Java数据结构主体的集合体系.其中包括: 1. Co ...
- sublime text3 php开发必要的插件
一.安装Sublime Text 3 官网 http://www.sublimetext.com/3 一定要选择ST3,而不是ST2,3比2好用,真的,后面你就知道了. 选择对应的版本安装.完事后,要 ...
- noip模拟题《迷》enc
[问题背景]zhx 和他的妹子聊天.[问题描述] 考虑一种简单的加密算法. 假定所有句子都由小写英文字母构成, 对于每一个字母, 我们将它唯一地映射到另一个字母.例如考虑映射规则:a- ...
- 【题解】CF#611 H-New Year and Forgotten Tree
有趣啊~手玩一下这棵树,发现因为连边只对相连点的位数有限制,我们可以认为是在往一棵已经有 m 个结点的树上挂叶子结点直到满足要求.(m = log(10) n).注意由于 m 超级无敌小,我们可以直接 ...
- 【刷题】HDU 1695 GCD
Problem Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD( ...