android-ndk gnustl_static exe不工作
我似乎无法得到以下琐碎的代码来编译/链接和问题似乎特定于std :: wstring和gnustl_static C++库。任何帮助,将不胜感激。android-ndk gnustl_static exe不工作
的main.cpp文件:
#include <string>
int main(void)
{
std::wstring wtest(L"Test");
return 0;
}
Application.mk文件:
APP_CFLAGS += -fexceptions
APP_STL := gnustl_static
Android.mk文件:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := TestWCharApp
LOCAL_CFLAGS := -D_GLIBCXX_USE_WCHAR_T
LOCAL_SRC_FILES := main.cpp
include $(BUILD_EXECUTABLE)
当试图链接使用gnustl_static我上面的应用得到以下错误信息:
undefined reference to `std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::basic_string(wchar_t const*, std::allocator<wchar_t> const&)'
如果我将APP_STL更改为stlport_static并定义_STLP_HAS_WCHAR_T,似乎所有内容都可以编译/链接/正常运行。我通过将exe上传到模拟器并通过shell运行来验证它的工作原理。
我将需要使用gnustl实现C++异常支持,否则我会去stlport_shared。关于为什么上述示例适用于stlport_static但不适用gnustl_static的任何线索?
这是一个与文件$ NDK /来源/ CXX-STL /问题的GNU的libstdC++/Android.mk
添加以下行该文件:
LOCAL_MODULE_FILENAME := libstdc++
从平台\ Android的 - * \弓臂的\ usr \包括\ wchar.h头文件:
/* IMPORTANT: Any code that relies on wide character support is essentially
* non-portable and/or broken. the only reason this header exist
* is because I'm really a nice guy. However, I'm not nice enough
* to provide you with a real implementation. instead wchar_t == char
* and all wc functions are stubs to their "normal" equivalent...
*/
滑稽虽然在Android模拟器显示,运行以下简单的程序,wchar_t的是4字节。
#include <stdio.h>
int main(void)
{
printf("Size of wchar is %d\n", sizeof(wchar_t));
return 0;
}
要考虑的另一件事。 JNI桥提供了两种编组字符串数据的有用方法。 GetStringUTFChars(返回const char )和GetStringChars(返回jchar)。多少字节,你认为一个jchar被定义为... 2.
wchar_t在所有Linux上都是4字节。 – 2012-11-26 00:59:15
目标操作系统是目前2.1(API级别7)。我会测试2.3,看看它是否有任何区别。我希望我能找到一些关于gnustl_static库特别相关的wchar_t支持的官方文档。 – Bellinghammer 2011-02-15 00:33:59