gradle - 如何在 ndk 中使用 cmake 设置 LOCAL_LDFLAGS/LOCAL_CPPFLAGS?
问题描述
如何使用 cmake 设置 LOCAL_CPPFLAGS/LOCAL_CFLAGS/LOCAL_LDFLAGS?我想减小这么大,但我读过的教程都是关于 mk 文件的。我应该在 cmakelists.txt 中做什么?
我直接设置了LOCAL_CPPFLAGS/LOCAL_CFLAGS/LOCAL_LDFLAGS,但是好像不行。
set(LOCAL_CPPFLAGS "${LOCAL_CPPFLAGS} -ffunction-sections,-fdata-sections")
set(LOCAL_CFLAGS "${LOCAL_CFLAGS} -ffunction-sections,-fdata-sections")
set(LOCAL_LDFLAGS "${LOCAL_LDFLAGS} -Wl,--gc-sections,--icf=safe")
解决方案
你应该能够使用这样的东西来做到这一点:
target_compile_options(mytarget PRIVATE -ffunction-sections -fdata-sections)
target_link_libraries(mytarget -Wl,--gc-sections,--icf=safe)
请注意,-ffunction-sections
在使用 NDK 的 Clang 时默认启用了一段时间。如果您使用的是 NDK r19c 或更高版本,我相信-fdata-sections
默认情况下也会启用。因此,您只需明确指定链接器标志。
推荐阅读
- javascript - 在集合中查找与 ID 数组匹配的文档
- macos - 在 zsh 中包含破折号的通配文件名中的解析错误
- asp.net-core - 在 EF Core 2.1 中执行异步不可选择的存储过程
- javascript - 在 Modal 中引导和嵌入内容
- knockout.js - oracle JET Combobox(dropdown) 值在填充空数组时不会消失
- rxjs - 带有“onload”事件的 fromEvent 运算符(壮举。动态创建的图像元素)
- android - 使用camera2 api android和opencvcamera2进行并行处理
- r - 如何绘制用一种缩放颜色着色并使用 plotly 包的饼图
- git - 如何从 git repo 仅下载给定版本的源?
- unity3d - Unity Fabric 版本在哪里?