NDK的APP_STL与APP_LDFLAGS

个人总结经验:

Application.mk

第一种情况

APP_ABI := armeabi
APP_STL := gnustl_static
APP_LDFLAGS := -static

可以正常编译通过,在模拟器android2.3.3与Android.4.2.2运行正常.


第二种情况:

APP_ABI := armeabi
APP_STL := gabi++_static
APP_LDFLAGS := -static

 fatal error : string: No such file or directory
1>   #include
1>                    ^
1>  compilation terminated.


第三种情况:

APP_ABI := armeabi
APP_STL := stlport_static
APP_LDFLAGS := -static

1>\tmp\ndk-user\tmp\build-stlport\ndk\sources\cxx-stl\gabi++\src\fatal_error.cc(65): error : undefined reference to 'dlopen'
1>\tmp\ndk-user\tmp\build-stlport\ndk\sources\cxx-stl\gabi++\src\fatal_error.cc(68): error : undefined reference to 'dlsym'
1>\tmp\ndk-user\tmp\build-stlport\ndk\sources\cxx-stl\gabi++\src\fatal_error.cc(72): error : undefined reference to 'dlclose'


第四种情况

APP_ABI := armeabi
APP_STL := c++_static
APP_LDFLAGS := -static

1>D:/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe : error : D:/android-ndk-r10d/platforms/android-19/arch-arm/usr/lib/libc.a(ctype_.o): multiple definition of 'isxdigit'
1>  D:/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: D:/android-ndk-r10d/sources/cxx-stl/llvm-libc++/libs/armeabi/thumb/libc++_static.a(isxdigit.o): previous definition here
1>D:/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe : error : D:/android-ndk-r10d/platforms/android-19/arch-arm/usr/lib/libc.a(wchar.o): multiple definition of 'wcrtomb'
1>  D:/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: D:/android-ndk-r10d/sources/cxx-stl/llvm-libc++/libs/armeabi/thumb/libc++_static.a(wcrtomb.o): previous definition here
1>D:/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe : error : D:/android-ndk-r10d/platforms/android-19/arch-arm/usr/lib/libc.a(wchar.o): multiple definition of 'wcsrtombs'
1>  D:/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: D:/android-ndk-r10d/sources/cxx-stl/llvm-libc++/libs/armeabi/thumb/libc++_static.a(wcsrtombs.o): previous definition here
1>D:/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe : error : D:/android-ndk-r10d/platforms/android-19/arch-arm/usr/lib/libc.a(wchar.o): multiple definition of 'wcstombs'
1>  D:/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: D:/android-ndk-r10d/sources/cxx-stl/llvm-libc++/libs/armeabi/thumb/libc++_static.a(wcstombs.o): previous definition here
1>D:/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe : error : D:/android-ndk-r10d/platforms/android-19/arch-arm/usr/lib/libc.a(wchar.o): multiple definition of 'mbsrtowcs'
1>  D:/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: D:/android-ndk-r10d/sources/cxx-stl/llvm-libc++/libs/armeabi/thumb/libc++_static.a(mbsrtowcs.o): previous definition here
1>D:/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe : error : D:/android-ndk-r10d/platforms/android-19/arch-arm/usr/lib/libc.a(wchar.o): multiple definition of 'mbstowcs'
1>  D:/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: D:/android-ndk-r10d/sources/cxx-stl/llvm-libc++/libs/armeabi/thumb/libc++_static.a(mbstowcs.o): previous definition here
1>\tmp\ndk-user\tmp\build-libc++\ndk\sources\cxx-stl\llvm-libc++\..\llvm-libc++abi\libcxxabi\src\Unwind\AddressSpace.hpp(357): error : undefined reference to 'dl_unwind_find_exidx'
1>\tmp\ndk-user\tmp\build-libc++\ndk\sources\cxx-stl\llvm-libc++\..\llvm-libc++abi\libcxxabi\src\Unwind\AddressSpace.hpp(357): error : undefined reference to 'dl_unwind_find_exidx'
1>\tmp\ndk-user\tmp\build-libc++\ndk\sources\cxx-stl\llvm-libc++\..\..\android\support\src\libdl_support.c(50): error : undefined reference to 'dlopen'
1>\tmp\ndk-user\tmp\build-libc++\ndk\sources\cxx-stl\llvm-libc++\..\..\android\support\src\libdl_support.c(57): error : undefined reference to 'dlsym'





转:http://blog.csdn.net/startwithdp/article/details/7050732

工作积累之NDK编译STL

方法:

1.在jni目录下新建Application.mk; 加入 APP_STL :=  stlport_static  右边的值还可以换成下面几个:

system - 使用默认最小的C++运行库,这样生成的应用体积小,内存占用小,但部分功能将无法支持

stlport_static - 使用STLport作为静态库,这项是Android开发网极力推荐的

stlport_shared - STLport 作为动态库,这个可能产生兼容性和部分低版本的Android固件,目前不推荐使用。

gnustl_static  - 使用 GNU libstdc++ 作为静态库

默认情况下STLPORT是不支持C++异常处理和RTTI,所以不要出现 -fexceptions 或 -frtti ,如果真的需要可以使用gnustl_static来支持标准C++的特性,但生成的文件体积会偏大,运行效率会低一些。

支持C++异常处理,在Application.mk中加入 LOCAL_CPPFLAGS += -fexceptions这句,同理支持RTTI,则加入LOCAL_CPPFLAGS += -frtti,这里再次提醒大家,第二条说的使用gnustl静态库,而不是stlport。

 强制重新编译 STLPort ,在Application.mk中加入 STLPORT_FORCE_REBUILD := true 可以强制重新编译STLPort源码,由于一些原因可能自己需要修改下STLPort库,一般普通的开发者无需使用此项

2. 在要使用STL的cpp文件中包含相关的头文件,并且使用using namespace std;



你可能感兴趣的:(android,root技术,工作经验)