【问题标题】:android-ndk gnustl_static exe not workingandroid-ndk gnustl_static exe 不工作
【发布时间】:2011-02-14 22:09:31
【问题描述】:

我似乎无法编译/链接以下琐碎的代码,并且该问题似乎特定于 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_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 的任何线索?

【问题讨论】:

    标签: android android-ndk


    【解决方案1】:

    $NDK/sources/cxx-stl/gnu-libstdc++/Android.mk 文件有问题

    将以下行添加到该文件:

    LOCAL_MODULE_FILENAME := libstdc++
    

    【讨论】:

      【解决方案2】:

      您的目标操作系统是什么?根据this threadgnustl_static 在 2.3 之前不支持 wchar_t。

      【讨论】:

      • 目标操作系统当前为 2.1(API 级别 7)。我将针对 2.3 进行测试,看看它是否有任何不同。我希望我能找到一些与 gnustl_static 库特别相关的关于 wchar_t 支持的官方文档。
      【解决方案3】:

      来自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(返回 const char )和 GetStringChars(返回 jchar)。你认为一个 jchar 定义为多少字节... 2.

      【讨论】:

      • wchar_t 在所有 Linux 上都是 4 个字节。
      【解决方案4】:

      确保您运行“ndk-build clean”并手动删除您的 libs/ 和 obj/ 目录。

      (Reference)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-15
        • 1970-01-01
        • 2012-01-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多