2011-02-14 61 views
3

我似乎無法得到以下瑣碎的代碼來編譯/鏈接和問題似乎特定於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的任何線索?

回答

1

這是一個與文件$ NDK /來源/ CXX-STL /問題的GNU的libstdC++/Android.mk

添加以下行該文件:

LOCAL_MODULE_FILENAME := libstdc++ 
1

什麼是您的目標操作系統?根據this threadgnustl_static不支持2.3之前的wchar_t。

+0

目標操作系統是目前2.1(API級別7)。我會測試2.3,看看它是否有任何區別。我希望我能找到一些關於gnustl_static庫特別相關的wchar_t支持的官方文檔。 – Bellinghammer 2011-02-15 00:33:59

1

從平臺\ 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.

+0

wchar_t在所有Linux上都是4字節。 – 2012-11-26 00:59:15

0

確保你運行「NDK,打造乾淨」並手動刪除您的庫/和OBJ/ 目錄。

Reference