Android.mk用法整理
[时间:2016-05] [状态:Open]
输出消息
由于Android.mk使用的GNU Make的语法,可以方便的使用。ndk提供了一下三种格式的消息输出:
- error: debug print + stop the build (输出信息并停止构建)
- info: basic debug print (仅输出消息)
- warning: same as info but displays the line number where it's been inserted (输出消息并显示当前行数)
具体用法如下:
$(error this is the error message that will stop the build process)
$(warning this the warning msg)
$(info this the info msg)
参考How to print a var in ndk-build
仅构建32位静态库、动态库、可执行文件
Android.mk支持通过下面变量配置仅编译32位。
LOCAL_32_BIT_ONLY := true
或者使用下面配置
TARGET_PREFER_32_BIT := true
或者使用LOCAL_MULTILIB变量配置32位、64位构建(会覆盖全局的TARGET_PREFER_32_BIT)。其值可选择:
- "both": build both 32-bit and 64-bit.
- "32": build only 32-bit.
- "64": build only 64-bit.
- "first": build for only the first arch (32-bit in 32-bit devices and 64-bit in 64-bit devices).
- "": the default; the build system decides what arch to build based on the module class and other LOCAL_ variables, such as LOCAL_MODULE_TARGET_ARCH, LOCAL_32_BIT_ONLY, etc.
参考Understanding 64-bit Builds(Android)
LOCAL_LDLIBS LOCAL_LDFLAGS LOCAL_SHARED_LIBRARIES区别在哪?
关于Android.mk中这三个变量的说明,找了下有几篇文章内容类似,比如http://blog.sina.cn/dpool/blog/s/blog_5da93c8f0102vdpc.html、android集成第三方静态库的编译方法、Android.mk的用法和基础&&m、mm、mmm编译命令,但说实话内容都差不多,没有介绍更详细的。
还是直接看英文的吧。
先看"Secrets of Android.mk"中的这三个变量的介绍:
LOCAL_SHARED_LIBRARIES
These are the libraries you directly link against. You don't need to pass transitively included libraries. Specify the name without the suffix。
用于指定需要直接链接的库,库的名字不需要后缀。同时会生成依赖关系,当库不存在时会去编译这个库。
具体用法如下:
LOCAL_SHARED_LIBRARIES := \
libutils \
libui \
libaudio
LOCAL_LDLIBS
LOCAL_LDLIBS allows you to specify additional libraries that are not part of the build for your executable or library. Specify the libraries you want in -lxxx format; they're passed directly to the link line. However, keep in mind that there will be no dependency generated for these libraries. It's most useful in simulator builds where you want to use a library preinstalled on the host. The linker (ld) is a particularly fussy beast, so it's sometimes necessary to pass other flags here if you're doing something sneaky.
链接的库不产生依赖关系,一般用于不需要重新编译的库,如库不存在,则会报错找不到。如果某一个库既有动态库又有静态库,那么链接的是动态库而非静态库。
用法如下:
LOCAL_LDLIBS += -lcurses -lpthread
LOCAL_LDLIBS += -Wl,-z,origin
LOCAL_LDFLAGS
You can pass additional flags to the linker by setting LOCAL_LDFLAGS. Keep in mind that the order of parameters is very important to ld, so test whatever you do on all platforms.
传递给链接器一个一些额外的参数,比如想传递给外面的库和库路径给ld,或者传递给ld linker的一些链接参数,-On,-EL{B}(大小端字节序)。
LOCAL_LDFLAGS += $(LOCAL_PATH)/lib/libavcodec.a
从stackoverflow中可以看到以下更详细的说明:
LOCAL_LDLIBS and LOCAL_SHARED_LIBRARIES are both used to link libraries. However LOCAL_SHARED_LIBRARIES is looking for intermediate objects and if not found the library is being rebuilt.
LOCAL_LDLIBS expects to find final library.
They both work under SDK and NDK.
The main differences are the following:(LOCAL_LDLIBS vs. LOCAL_LDFLAGS)
LOCAL_LDFLAGS appear before the list of object files and libraries on the final linker command-line, this is where you want to put actual "flags" that affect linker behaviour.
LOCAL_LDLIBS appear after the list of object files and libraries on the final linked command-line, this is where you want to put actual system library dependencies.
The distinction exists because of the way static linking works on Unix, i.e. the order of object files, static libraries and shared libraries is very important to determine the final result, and sometimes you really to ensure that something appears before / after the other
所以在使用的时候建议按照下面规则:
- Put real linker flags into LOCAL_LDFLAGS(将实际需要编译链接的符号放到LOCAL_LDFLAGS中)
- Put system library dependencies into LOCAL_LDLIBS (将对系统库的依赖放到LOCAL_LDLIBS中)
- Only use LOCAL_LDLIBS for system library dependencies. If you want to point to another library, it's much better to list them in either LOCAL_STATIC_LIBRARIES and LOCAL_SHARED_LIBRARIES (even if this means defining a PREBUILT_XXX module for them), because this lets the build system work out dependencies and ordering automatically for you.(LOCAL_LDLIBS仅用于指定系统库的依赖性。如果需要其他库,建议使用LOCAL_STATIC_LIBRARIES/LOCAL_SHARED_LIBRARIES)
参考:
- Secrets of Android.mk
- http://stackoverflow.com/questions/22354041/local-ldlibs-vs-local-ldflags
- http://stackoverflow.com/questions/22756435/local-ldlibs-doesnt-work-but-local-ldflags-works-why
Android.mk用法整理的更多相关文章
- Android spannableStringBuilder用法整理
Android spannableStringBuilder用法整理 分类: Android开发2013-11-29 10:58 5009人阅读 评论(0) 收藏 举报 Androidspannabl ...
- Android.mk 用法介绍
一个Android.mk file用来向编译系统描述你的源代码.具体来说:该文件是GNU Makefile的一小部分,会被编译系统解析一次或多次.你可以在每一个Android.mk file中定义一个 ...
- Android.mk用法详解
一.Android.mk介绍 Android.mk是Android提供的一种makefile文件,用来指定诸如编译生成so库名.引用的头文件目录.需要编译的.c/.cpp文件和.a静态库文件等.要掌握 ...
- Android.mk使用第三方库方法
/********************************************************************** * Android.mk使用第三方库方法 * 说明: * ...
- 【整理修订】Android.mk详解
Android.mk详解 1. Android.mk 的应用范围 Android.mk文件是GNU Makefile的一小部分,它用来对Android程序进行编译. 一个Android.mk文件可以编 ...
- Android.mk 基本应用
如果是在android源码里面编译我们自己的应用,就需要这个android.mk文件,这个文件就告诉android系统应用如何来编译这个应用以及这个应用它所依赖哪些文件等等信息.我对android.m ...
- Android.mk相关知识
Android.mk是Android提供的一种makefile文件,用来指定诸如编译生成so库名.引用的头文件目录.需要编译的.c/.cpp文件和.a静态库文件等.要掌握jni,就必须熟练掌握Andr ...
- Android.mk的用法和基础【转】
一个Android.mk file用来向编译系统描述你的源代码.具体来说:该文件是GNU Makefile的一小部分,会被编译系统解析一次或多次.你可以在每一个Android.mk file中定义一个 ...
- Android.mk详解
Android.mk是Android提供的一种makefile文件,用来指定诸如编译生成so库名.引用的头文件目录.需要编译的.c/.cpp文件和.a静态库文件等.要掌握jni,就必须熟练掌握Andr ...
随机推荐
- iOS 中的各种锁
在日常开发过程中,为了提升程序运行效率,以及用户体验,我们经常使用多线程.在使用多线程的过程中,难免会遇到资源竞争问题.我们采用锁的机制来确保线程安全. 线程安全 当一个线程访问数据的时候,其他的线程 ...
- Nginx防盗链的3种方法 文件防盗链 图片防盗链 视频防盗链 linux防盗链
Nginx 是一个很牛的高性能Web和反向代理服务器, 它具有有很多非常优越的特性: 在高连接并发的情况下,Nginx是Apache服务器不错的替代品,目前Web服务器调查显示Apache下降Ngni ...
- 树莓派进阶之路 (003) - Raspberry Pi(树莓派)国内软件源
树莓派自带的软件源是 deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi 由于网站在国外 ...
- ios面试题来一波
一.如果让你实现属性的weak,如何实现的? PS: @property 等同于在.h文件中声明实例变量的get/set方法, 而其中property有一些关键字,其中就包括weak,atomic的. ...
- 【Algorithm】二分查找
今天在学习<编程之美>的时候,看到一个二分查找的题目,发现原来我真的不懂二分查找. 二分查找时候注意的事项: 在求二分查找的中间点时没有使用 midIndex = (minIndex + ...
- 【Linux】字符转换命令join
join 看字面上的意义 (加入/参加) 就可以知道,他是在处理两个文件之间的数据,而且,主要是在处理『两个文件当中,有 "相同数据" 的那一行,才将他加在一起』的意思.我们利用底 ...
- spark运行模式
一.Spark运行模式 Spark有以下四种运行模式: local:本地单进程模式,用于本地开发测试Spark代码; standalone:分布式集群模式,Master-Worker架构,Master ...
- selenium实战脚本集(2)——简单的知乎爬虫
背景 很多同学在工作中是没有selenium的实战环境的,因此自学的同学会感到有力无处使,想学习但又不知道怎么练习.其实学习新东西的道理都是想通的,那就是反复练习.这里乙醇会给出一些有用的,也富有挑战 ...
- appium简明教程(11)——使用resource id定位(仅支持安卓4.3以上系统)
上一节乙醇带大家了解了appium的定位策略.实际上appium的控件定位方式是完全遵守webdriver的mobile扩展协议的. 这一节将分享一下如何使用resource id来定位android ...
- 例说Linux内核链表(一)
介绍 众所周知,Linux内核大部分是使用GNU C语言写的.C不同于其它的语言,它不具备一个好的数据结构对象或者标准对象库的支持. 所以能够借用Linux内核源代码树的循环双链表是一件非常值得让人高 ...