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

转自:http://www.cocos2d-x.org/news/307

By zhangxm Posted  8 months ago  Comments 20

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.

If you use NDK r10 to build cocos2d-x v3.2, you will meet a compiling error of all tests and linking error of lua tests.

compiling error

The error message is

/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 here
    long int tell();

This compiling error is fixed in this patch. We are sorry about 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

NDK r9d url

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值