3

我开始使用相当复杂的程序使用 NDK 遇到有趣的错误:

#include <stdio.h>
#include <iostream>

int main( int argc, char **argv ) {
    return 0;
}


>call c:\android-ndk-r9\ndk-build.cmd
"Compile++ thumb : test <= test.cpp
In file included from C:/workspace/c++11_test//jni/test.cpp:11:
In file included from c:/android-ndk-r9/sources/cxx-stl/stlport/stlport\iostream:43:
In file included from c:/android-ndk-r9/sources/cxx-stl/stlport/stlport\stl/_istream.h:31:
In file included from c:/android-ndk-r9/sources/cxx-stl/stlport/stlport\stl/_ostream.h:380:
In file included from c:/android-ndk-r9/sources/cxx-stl/stlport/stlport\stl/_ostream.c:26:
In file included from c:/android-ndk-r9/sources/cxx-stl/stlport/stlport\stl/_num_put.h:180:
In file included from c:/android-ndk-r9/sources/cxx-stl/stlport/stlport\stl/_num_put.c:26:
c:/android-ndk-r9/sources/cxx-stl/stlport/stlport\stl/_limits.h:217:48: error: non-type template argument evaluates to -2147483648, which cannot be narrowed to type 'wchar_t'
      [-Wc++11-narrowing]
  : public _STLP_PRIV _Integer_limits<wchar_t, WCHAR_MIN, WCHAR_MAX, -1, true>
                                               ^
c:/android-ndk-r9/platforms/android-14/arch-arm/usr/include\../include/wchar.h:76:22: note: expanded from macro 'WCHAR_MIN'
#define  WCHAR_MIN   INT_MIN
                     ^
c:/android-ndk-r9/platforms/android-14/arch-arm/usr/include\sys/limits.h:69:18: note: expanded from macro 'INT_MIN'
#define INT_MIN         (-0x7fffffff-1) /* min value for an int */
                        ^
1 error generated.

make: * [C:/workspace/c++11_test//obj/local/armeabi/objs/test/test.o] 错误1

这是ndk-r94.8编译就好了,只有clang偶然发现它。我是否需要定义一些东西才能使 clang 工作?我试过谷歌错误,但没有任何相关信息......显然,我可以使用-Wno-c++11-narrowing将其关闭,但我不想禁用缩小检查。

而且它只显示stlport_static , gnustl_static没有错误

4

1 回答 1

0

您似乎已启用 C++11,因为您收到此警告。

STLport 对 C++11 的支持不是很好。我怀疑这就是你痛苦的原因。

修复需要更改 STLport,或从 clang 命令行中删除“-std=c++11”开关。

恕我直言,我建议切换到 gnustl(又名 libstdc++),除非有其他原因阻止您这样做(许可:libstdc++ 是GPL3,但有一些可能对 clang 有效或无效的重大例外 - 您应该确定为您自己)、遗留支持、大小等)。我在这方面有很好的经验。

于 2013-09-03T08:54:42.390 回答