如题所示的NDK编译错误是什么原因导致的?
我的困惑
今天在把WIN32下的一个工程移植到ANDROID时遇到上述错误,感到非常困惑。错误如下:
D:/ndkr8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/../lib/gcc/
arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld.exe: Warnin
g: ./obj/local/armeabi/webp.a(alpha.o): Unknown EABI object attribute 44
D:/ndkr8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/../lib/gcc/
arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld.exe: Warnin
..............................................................................(others omitted)
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/libgame_shared.so] Error 1
make: Leaving directory `/cygdrive/e/download2010/cocos2d-x/cocos2d-2.1rc0-x-2.1
.2/LittleWordNinjaAnd/proj.android'
也就是说,我的错误与http://www.eoeandroid.com/thread-263553-1-1.html处这位难友相同。他提交的错误信息是:
E:/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld.exe: Dwarf Error: mangled line number section.
./obj/local/armeabi/webp.a(frame.o): In function `StoreSideInfo':
frame.c:(.text.StoreSideInfo+0xb4): undefined reference to `__gnu_thumb1_case_si'
collect2: ld returned 1 exit status
/cygdrive/e/android-ndk-r8/build/core/build-binary.mk:369: recipe for target `obj/local/armeabi/libgame.so' failed
make: *** [obj/local/armeabi/libgame.so] Error 1
make: 离开目录“/cygdrive/e/cocos2dx/cocos2d-2.1rc0-x-2.1.2/cocosdemo/proj.android”
出错信息如上,是因为我的cygwin少下了什么组件吗?
目前找到的中文参考有:
1.http://blog.csdn.net/huangtaiquan/article/details/7090901
文章如下:
今天出现了编译的时候,把项目src中的文件都编译成.o文件后,把所有的.o文件整合成为可执行文件的时候,出现了ld: Dwarf Error: mangled line number section. 错误提示。
后来发现原因是由于调用其他的lib,但是某个lib是使用gcc-4.6版本编译的。而当前使用gcc-4.1版本。故使用gcc-4.1重新生成新的lib后,就不会出现问题了。
2.http://blog.csdn.net/lwuit/article/details/7906104
她提示的信息有:
在编译cocos2d-x的helloworld 或者 tests的时候。
官网上使用ndk4、ndk5,这里是使用 ndkr7b、ndkr8或ndkr8b 。操作会简单很多,但是出了些小问题也是很坑人的。
下面出现如下编译错误
[javascript] view plaincopy
Prebuilt : libgnustl_static.a <= <NDK>/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/
SharedLibrary : libcocos2d.so
g:/handgame/tools/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/
[javascript] view plaincopy
windows/bin/../lib/gcc/arm-linux-androideabi/4.6.x-google/../../../../arm-linux-
[javascript] view plaincopy
androideabi/bin/ld.exe: cannot find ./obj/local/armeabi/libgnustl_static.a:
[javascript] view plaincopy
Permission denied
collect2: ld returned 1 exit status
/cygdrive/g/HandGame/tools/android-ndk-r8b/build/core/build-binary.mk:378:
[javascript] view plaincopy
recipe for target `obj/local/armeabi/libcocos2d.so' failed
在helloworld中找到Application.mk文件添加如下内容:STLPORT_FORCE_REBUILD := true
3.http://www.eifr.com/article.php?id=603
有作用的提示有:
在Linux下创建线程时,编译时会出现下面的错误,
[root@linuxserver 807]# gcc -o 22 22.c
/tmp/cc21HcoW.o(.text+0x4c): In function `main':
: undefined reference to `pthread_create'
collect2: ld returned 1 exit status...........................
此时,只需改变编译方式
将gcc -o 22 22.c 改变为 gcc -O2 -Wall -o 22 22.c -lpthread
最关键的是-lpthread
根据错误
/tmp/cc21HcoW.o(.text+0x4c): In function `main':
: undefined reference to `pthread_create'
collect2: ld returned 1 exit status
可以看出是在ld的时候系统无法找到pthread_create函数。也就是说编译器在link得时候找不到其中的一个使用库的函数。
如果差pthread_create的话可以发现其在pthread.so中,所以需要增加 -lpthread编译参数,告诉linker在link的时候使用pthread模块
英文参考
又找到一篇英文参考如下:
URL: http://stackoverflow.com/questions/11715999/ndk-build-causes-error
3 down votefavorite | I had been trying to solve this issue for quiet a long time,I am using a library called FreeImage and when tries to do the NDK build the code results in following error My source can be downloaded from copy.html">http://www.4shared.com/zip/1C3vpLI7/android-p_w_picpathfilter-ndk_copy.html Thanking you in advance for your valuable efforts- tribute.cpp+0x8): undefined reference to `std::ios_base::Init::Init()' ImfChromaticitiesAttribute.cpp:(.text.startup._GLOBAL__sub_I_ImfChromaticitiesAttribute.cpp+0x24): undefined reference to `std::ios_base::Init::~Init()' /home/flock/ANDROID/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: Dwarf Error: mangled line number section. ./obj/local/armeabi/libfreep_w_picpath.a(ImfCompressionAttribute.o): In function `_GLOBAL__sub_I_ImfCompressionAttribute.cpp':ImfCompressionAttribute.cpp:(.text.startup._GLOBAL__sub_I_ImfCompressionAttribute.cpp+0x8): undefined reference to `std::ios_base::Init::Init()' ImfCompressionAttribute.cpp:(.text.startup._GLOBAL__sub_I_ImfCompressionAttribute.cpp+0x24): undefined reference to `std::ios_base::Init::~Init()' ./obj/local/armeabi/libfreep_w_picpath.a(ImfCompressor.o): In function `Imf::newCompressor(Imf::Compression, unsigned int, Imf::Header const&)':ImfCompressor.cpp:(.text._ZN3Imf13newCompressorENS_11CompressionEjRKNS_6HeaderE+0x10): undefined reference to `__gnu_thumb1_case_uqi' ImfCompressor.cpp:(.text._ZN3Imf13newCompressorENS_11CompressionEjRKNS_6HeaderE+0xb8): undefined reference to `__cxa_end_cleanup' ./obj/local/armeabi/libfreep_w_picpath.a(ImfCompressor.o):(.ARM.extab.text._ZN3Imf13newCompressorENS_11CompressionEjRKNS_6HeaderE+0x0): undefined reference to `__gxx_personality_v0'./obj/local/armeabi/libfreep_w_picpath.a(ImfCompressor.o): In function `Imf::newTileCompressor(Imf::Compression, unsigned int, unsigned int, Imf::Header const&)': ImfCompressor.cpp:(.text._ZN3Imf17newTileCompressorENS_11CompressionEjjRKNS_6HeaderE+0x12): undefined reference to `__gnu_thumb1_case_uqi' ImfCompressor.cpp:(.text._ZN3Imf17newTileCompressorENS_11CompressionEjjRKNS_6HeaderE+0x64): undefined reference to `__cxa_allocate_exception'ImfCompressor.cpp:(.text._ZN3Imf17newTileCompressorENS_11CompressionEjjRKNS_6HeaderE+0x8a): undefined reference to `__cxa_throw' ImfCompressor.cpp:(.text._ZN3Imf17newTileCompressorENS_11CompressionEjjRKNS_6HeaderE+0xe4): undefined reference to `__cxa_end_cleanup' ./obj/local/armeabi/libfreep_w_picpath.a(ImfCompressor.o):(.ARM.extab.text._ZN3Imf17newTileCompressorENS_11CompressionEjjRKNS_6HeaderE+0x0): undefined reference to `__gxx_personality_v0'./obj/local/armeabi/libfreep_w_picpath.a(ImfCompressor.o): In function `_GLOBAL__sub_I_ImfCompressor.cpp': ImfCompressor.cpp:(.text.startup._GLOBAL__sub_I_ImfCompressor.cpp+0x8): undefined reference to `std::ios_base::Init::Init()' ImfCompressor.cpp:(.text.startup._GLOBAL__sub_I_ImfCompressor.cpp+0x24): undefined reference to `std::ios_base::Init::~Init()'./obj/local/armeabi/libfreep_w_picpath.a(ImfCompressor.o):(.data.rel.ro+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info' /home/flock/ANDROID/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: Dwarf Error: mangled line number section. ./obj/local/armeabi/libfreep_w_picpath.a(ImfConvert.o): In function `_GLOBAL__sub_I_ImfConvert.cpp': ImfConvert.cpp:(.text.startup._GLOBAL__sub_I_ImfConvert.cpp+0x8): undefined reference to `std::ios_base::Init::Init()'ImfConvert.cpp:(.text.startup._GLOBAL__sub_I_ImfConvert.cpp+0x24): undefined reference to `std::ios_base::Init::~Init()' /home/flock/ANDROID/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: Dwarf Error: mangled line number section. ./obj/local/armeabi/libfreep_w_picpath.a(ImfDoubleAttribute.o): In function `_GLOBAL__sub_I_ImfDoubleAttribute.cpp': ImfDoubleAttribute.cpp:(.text.startup._GLOBAL__sub_I_ImfDoubleAttribute.cpp+0x8): undefined reference to `std::ios_base::Init::Init()'ImfDoubleAttribute.cpp:(.text.startup._GLOBAL__sub_I_ImfDoubleAttribute.cpp+0x24): undefined reference to `std::ios_base::Init::~Init()' /home/flock/ANDROID/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: Dwarf Error: mangled line number section. ./obj/local/armeabi/libfreep_w_picpath.a(ImfEnvmapAttribute.o): In function `_GLOBAL__sub_I_ImfEnvmapAttribute.cpp': ImfEnvmapAttribute.cpp:(.text.startup._GLOBAL__sub_I_ImfEnvmapAttribute.cpp+0x8): undefined reference to `std::ios_base::Init::Init()'ImfEnvmapAttribute.cpp:(.text.startup._GLOBAL__sub_I_ImfEnvmapAttribute.cpp+0x24): undefined reference to `std::ios_base::Init::~Init()' |
My Android.mk
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE:= freep_w_picpath LOCAL_SRC_FILES :=libfreep_w_picpath.a include $(PREBUILT_STATIC_LIBRARY)include $(CLEAR_VARS)LOCAL_MODULE:= p_w_picpathprocessing LOCAL_SRC_FILES:= p_w_picpathprocessing.c LOCAL_STATIC_LIBRARIES = freep_w_picpath LOCAL_EXPORT_C_INCLUDES := freep_w_picpath.h LOCAL_LDLIBS:= -lm -llog -ljnigraphics include $(BUILD_SHARED_LIBRARY)
My application.mk
APP_OPTIM := release APP_PLATFORM. := android-8APP_STL := gnustl_static APP_CPPFLAGS += -frtti APP_CPPFLAGS += -fexceptions APP_CPPFLAGS += -DANDROID APP_ABI:= armeabi
接下来是可能的一些师傅们的回答(跟帖):
What do your Android.mk and Application.mk files look like?– Michael Jul 30 '12 at 5:56 | |
@Michael....Please see the edit – Sreekanth Karumanaghat Jul 30 '12 at 6:03 | |
Looks like libfreep_w_picpath.a had been compiled incorrectly. Try to compile it exactly with same Android NDK you are compiling. Or better - dontuse static library. include the Android.ml makefile of FreeImage, and compile together with your code - it will guarantee that you won't have this kind of problem. – Mārti愁 Mo攁椀欀漀 Jul 30 '12 at 6:12 | |
What ABI are you building for? I see undefined references that indicate that some of the code was built for ARM, but you seem to be using an x86 toolchain. – Michael Jul 30 '12 at 6:17 | |
@Martins Mozeiko...Hi I had been using a downloaded version of libfreep_w_picpath.a...How can I make my code to work? – Sreekanth KarumanaghatJul 30 '12 at 6:31 |
关闭cygwin,再次打开重新编译,得到如下错误:
真是莫名其妙???!!!
......
After a long time of trying trying... I used the following solution:
最后,我基本同意1.http://blog.csdn.net/huangtaiquan/article/details/7090901朋友提到的看法。现在,我重新使用了2.1.1,再重新走一遍上面的过程。OK!!!!!!!!
另外,还得到如下一些教训与您一起分享:
第一,GCC编译器比较于VC++更为严格,也就是说,你在WIN32下通过,在NDK下很可能存在问题。不过,问题不太大,你根据提示,作逐一修改即可。例如:
我的程序在WIN32下调试时,许多的.h或者.cpp文件编码使用的是UNICODE或者ANSI,而这很可能在NDK编译下存在问题。一般地,你只需要把它们的编码修改为UTF-8即可。
我使用的工具是,EditPlus,感觉这个工具还是相当方便的。在许多情况下开启许多文字型文件时你不需要启动大型的工具,例如VS,即可达到修改的目的。
第二,在WIN32编程时在resource文件夹下命名各种资源,主要是png文件,建议统一使用小写。而且,在CPP文件中引用时也要保持一致的大小写。否则,当你最后使用ECLIPSE下构建工程时可能会出现一连串的错误提示,例如assets下的某个png文件没有找到之类的。
当然,我是在我的WIN7+ECLIPSE+VS2010+COCOS2D-X 2.1.1平台上得到如上结论的。对于你们则应当视自己的环境而定。
总之,上面错误我还是没有彻底解决,只是放弃了,而且选择了2.1.1版本的COCOS2D-X罢了。
补充:我目前之所以想选择最新的2.1.2是因为其中有一个我需要的CCEDITBOX,在WIN32下测试CCEDITBOX是没有问题的。但是,以前的版本下,如果不是使用例如
网络上其他的自己开发方式,是无法使用的。这一点,你在网络的其他文章中也会得到这个结论。我是在2.1.2下调试通过CCEDITBOX,然后再挪动到2.1.1下的(就是说在
这个版本下通过不了不要紧--只是CCEDITBOX这一小块)。然后,拿到NDK下编译就行。
2013.5.19新参考内容添加如下:
1.http://cocos2d.cocoachina.com/bbs/forum.php?mod=viewthread&tid=10750处提到:
“这个问题我也遇到,我的解决理法是更新ndk到版本 android-ndk-r8e”
2.http://www.eoeandroid.com/thread-263553-1-1.html处提到:
“卧了个大槽,把NDK升级到最新版编译通过了。”
喜获成功
记得前几天看到COCOS2D-X官方网站还提到说是COCOS2D-X 2.1.3版本在目前典型的NDK下编译成功的,于是不死心,毕竟最新版本中提供了许多更好使用的功能,而且也消除了以前的不少BUG。于是,使用上面提到的方法,下载了NDKR8E,其他的没有变(只是有关路径设置位置由原来的NDK版本更改到现在版本),重新在CYGWIND下编译项目,终于成功了!!!
提示:我的GCC还是以前的版本1.4.4.
无标题.jpg
转载于:https://blog.51cto.com/zhuxianzhong/1531748