Compiling and linking error when using NDK r10 to build cocos2d-x v3.2

news/2024/11/17 0:17:31/

用ndk r10编译cocos2dx 3.2的时候会报出如下错误信息:

/Users/minggo/SourceCode/cocos2d-x/build/../cocos/./3d/CCBundleReader.cpp:94:23: error: return type of out-of-line definition of 'cocos2d::BundleReader::tell'differs from that in the declaration
ssize_t BundleReader::tell()^
/Users/minggo/SourceCode/cocos2d-x/build/../cocos/./3d/CCBundleReader.h:90:14: note: previous declaration is herelong int tell();


NDK r10 has problem, refer to [this ticket](https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=73907). We suggest you not use it.


linking error

After fixing the compiling error, you will meet linking error when building lua test cases or new lua projects

/Users/minggo/bin/android/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /Users/minggo/bin/android/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.8/libgcc.a(pr-support.o): multiple definition of '_Unwind_GetRegionStart'
/Users/minggo/bin/android/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: /Users/minggo/bin/android/android-ndk-r10/sources/cxx-stl/llvm-libc++/libs/armeabi/thumb/libc++_static.a(Unwind-EHABI.o): previous definition here
/Users/minggo/bin/android/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: /Users/minggo/bin/android/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.8/libgcc.a(pr-support.o): multiple definition of '_Unwind_GetLanguageSpecificData'
/Users/minggo/bin/android/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: /Users/minggo/bin/android/android-ndk-r10/sources/cxx-stl/llvm-libc++/libs/armeabi/thumb/libc++_static.a(Unwind-EHABI.o): previous definition here
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

I have created a ticket in Android issue system for it. And NDK developers confirmed it is a bug of NDK r10. And he gave two ways to work around it:

  • requires makefile changes to drop libgcc.a with command line reads "-nodefaultlibs -lstdc++ -latomic -ldl -lm -lc -lcompiler_rt_static"

    Because we don't use standalone toolchain, so changing makefile doesn't work for cocos2d-x.

  • use libc++_shared.so and add LIBCXX_USE_GABIXX:=true in Application.mk which force rebuild libc++ to use gabi++

    This method requires to use shared library and modify Cocos2dxActivity.java to load dependened shared library. We don't want to modify like this, because:

    • We haven't used shared library before which means we haven't tested
    • It will make .apk 0.13M bigger then using static library
    • Google guy will fix it in next NDK version

conclusion

We suggest you not to use NDK r10. Please use NDK r9d instead. If you want to use NDK r10, the following steps can help you work around it:

  • Change long int to ssize_t in the declaration of BundleReader::tell(). You can refer to this pull request for detail information.
  • Change APP_STL:=c++_static to APP_STL:=c++_shared, add LIBCXX_USE_GABIXX:=true inApplication.mk, and modify your java activity code to load libc++_shared.so. You can refer to this commitfor more detail information


按照conclusion修改完之后,还需要在AppActivity中进行如下修改:

讲AppActivity修改成如下形式就行了:

public class AppActivity extends Cocos2dxActivity {
static {
System.loadLibrary("compiler_rt_shared");
System.loadLibrary("c++_shared");
}
}



http://www.ppmy.cn/news/182347.html

相关文章

EN45545-2 R10地面材料防火测试

高铁、动车组、地铁等轨道车辆用水平朝上表面材料、地板等地面材料根据EN45545-2 R10标准进行测试及评估。 EN45545-2-2013 Railway applications - Fire protection of railway vehicles-Part 2: Requirement for fire behavior of materials and components EN45545-2-2013铁…

使用h5Stream实现监控视频实时显示

准备工作: 下载安装 相关文档手册 下载h5s-r10.6.0229.20-win64-release.zip 下载VC_redist.x64.2017.exe 开始 安装VC_redist.x64.2017.exe 安装完成之后需要进行重启 解压h5s-r10.6.0229.20-win64-release.zip到任意目录,要注意,目录…

android-ndk-r10交叉编译libev(ubuntu16.04)

android-ndk-r10交叉编译libev(ubuntu16.04) 版本说明 版本作者日期备注0.1loon2020.8.18初稿 目录 文章目录 android-ndk-r10交叉编译libev(ubuntu16.04)版本说明目录一、准备1、ndk下载2、libev下载 二、ndk安装1、解压安装2、配置环境变量3、验证环境变量 三、libev交叉编…

假设每磁道划分成10个物理块,每块存放1个逻辑记录。逻辑记录R1,R2,…

一个经典的操作系统题目: 数据存储在磁盘上的排列方式会影响I/O服务的总时间。假设每磁道划分成10个物理块,每块存放1个逻辑记录。逻辑记录R1,R2,…,R10存放在同一个磁道上,记录的安排顺序如下表所示&…

服务器磁盘raid0,raid1,raid10,raid5,raid50,raid6,raid60 分析与案例

1,raid0的特性:采用剥离,数据将在几个磁盘上进行分割。数据被分成很多数据块,每一数据块会被写入不同的磁盘。从而,每一磁盘的工作负荷都得到了降低,这有助于加速数据传输。RAID-0可让磁盘更好地响应&#…

【Android】android ndk r10 环境配置

android sdk 更新到 r23 时,eclipse 自带 adt版,里面并没有设置ndk的路径,从而导致了在ndk配置方面的难度。本文主要适合: ① 使用 android sdk r23 20140702 的朋友 ② 使用 android ndk r10 的朋友 ③ 想知道andorid adt自带ecl…

一文看懂JDK12中新版垃圾回收器-Shenandoah GC

目录 1. 简介 2. 流程 3. 实现 3.1. GC 前 3.2. GC 疏散阶段(Concurrent Evacuation) 3.3. GC 更新引用阶段(Concurrent Update References) 3.4. GC更新引用阶段(Final Update Refs ) 4. 对象比较…

安装R语言(Rstudio、R、RTools)

安装R语言(Rstudio、R、RTools) 本文介绍一下从零搭建R环境。 那么R语言,RTools和Rstudio有什么区别? R是基本的编程语言,单纯使用R是可以的,如图: image-20221207112951762 为了编写R程序,单独…