我似乎无法编译/链接以下简单的代码,而且这个问题似乎是std::wstring和gnustl_static C++库所特有的。任何帮助都将不胜感激。
main.cpp文件:
#include <string>
int main(void)
{
std::wstring wtest(L"Test");
return 0;
}Application.mk文件:
APP_CFLAGS += -fexceptions
APP_STL := gnustl_staticAndroid.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,有什么线索吗?
发布于 2011-03-31 14:41:19
文件$NDK/sources/cxx-stl/gnu-libstdc++/Android.mk有问题
将以下行添加到该文件:
LOCAL_MODULE_FILENAME := libstdc++发布于 2011-02-15 06:28:41
你的目标操作系统是什么?根据this thread的说法,gnustl_static在2.3版本之前不支持wchar_t。
发布于 2011-02-16 01:16:12
从platforms\android-*\arch-arm\usr\include\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 (返回常量字符)和GetStringChars (返回jchar)。你认为jchar有多少字节被定义为... 2。
https://stackoverflow.com/questions/4997855
复制相似问题