博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android.mk用法整理
阅读量:6420 次
发布时间:2019-06-23

本文共 4008 字,大约阅读时间需要 13 分钟。

[时间: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)

参考

仅构建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.

参考

LOCAL_LDLIBS LOCAL_LDFLAGS LOCAL_SHARED_LIBRARIES区别在哪?

关于Android.mk中这三个变量的说明,找了下有几篇文章内容类似,比如http://blog.sina.cn/dpool/blog/s/blog_5da93c8f0102vdpc.html、、,但说实话内容都差不多,没有介绍更详细的。

还是直接看英文的吧。
先看"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 -lpthreadLOCAL_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)

参考:

转载地址:http://yilra.baihongyu.com/

你可能感兴趣的文章
真正的上锁前,为何要调用preempt_disable()来关闭抢占的case【转】
查看>>
ASP.NET程序开发范例宝典
查看>>
Windows 8 C#调用C++编写的Windows运行时组件
查看>>
ip的划分,超详细
查看>>
Ubuntu 14.04安装LAMP(Linux,Apache,MySQL,PHP)
查看>>
云计算成朝阳产业,未来发展已成趋势
查看>>
一个帖子掌握android所有控件、ProgressBar 、Android 动画效果、SQLite、四大组件、Android多媒体(转...
查看>>
项目开发容易出错情况统计
查看>>
Foundations of Python Network Programming - 读书笔记系列(2) - Web Services
查看>>
thinkphp中配置信息的二维数组设置与使用
查看>>
BMap:JavaScript API
查看>>
浅谈SQL Server中的事务日志(三)----在简单恢复模式下日志的角色
查看>>
第 26 章 MySQL
查看>>
How far away ?(DFS)
查看>>
C#中三种截屏方式总结
查看>>
c#中取整,向上取,向下取
查看>>
移动端HTML5音频与视频问题及解决方案
查看>>
C# DLL资源文件打包(图片、JS、CSS)[WebResource]
查看>>
[MFC] MFC 获取指定窗口截图(大小可调)
查看>>
【c++】构造函数初始化列表中成员初始化的次序性
查看>>