Android NDK16错误(&#34;运算符&#39;&lt;&lt;&#39;是不明确的(操作数类型&#39; basic_ostream <char,std :: char_traits <char =“”>&gt;&#39 ;&#39; long long&#39;)&#34;

时间:2017-12-26 17:11:56

标签: android c++11 android-ndk clang++

为了尝试从NDK 15c过渡到NDK16b,我遇到了编写遗留代码的障碍,该代码试图将64位长的值写入ostream。

我已经搜索了NDK头文件,在std/_ostream中我觉得如果定义了#ifdef _STLP_LONG_LONG,那么ostream运算符应该支持我尝试做的事情。< / p>

我无法看到启用此功能需要做什么。我尝试用-D_STLP_LONG_LONG来定义它无济于事。

我的工具链正在使用NDK中的clang编译器。

这是实际的编译器输出:

MyInfo.cc:6499:33: error: use of overloaded operator '<<' is ambiguous (with operand types 'basic_ostream<char, std::char_traits<char> >' and 'long long')
      os << basename << ":" << (long long) val;
      ~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~
/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../include/c++/4.9.x/stl/_ostream.h:104:10: note: candidate function
_Self& operator<<(unsigned char __x) { _M_put_char(__x); return *this; }
     ^
/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../include/c++/4.9.x/stl/_ostream.h:106:10: note: candidate function
_Self& operator<<(short __x);
     ^
/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../include/c++/4.9.x/stl/_ostream.h:107:10: note: candidate function
_Self& operator<<(unsigned short __x);
     ^
/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../include/c++/4.9.x/stl/_ostream.h:108:10: note: candidate function
_Self& operator<<(int __x);
     ^
/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../include/c++/4.9.x/stl/_ostream.h:110:10: note: candidate function
_Self& operator<<(unsigned int __x);
     ^
/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../include/c++/4.9.x/stl/_ostream.h:117:10: note: candidate function
_Self& operator<<(long __x);
     ^
/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../include/c++/4.9.x/stl/_ostream.h:118:10: note: candidate function
_Self& operator<<(unsigned long __x);
     ^
/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../include/c++/4.9.x/stl/_ostream.h:123:10: note: candidate function
_Self& operator<<(float __x);
     ^
/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../include/c++/4.9.x/stl/_ostream.h:124:10: note: candidate function
_Self& operator<<(double __x);
     ^
/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../include/c++/4.9.x/stl/_ostream.h:126:10: note: candidate function
_Self& operator<<(long double __x);
     ^
/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../include/c++/4.9.x/stl/_ostream.h:130:10: note: candidate function
_Self& operator<<(bool __x);
     ^
/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../include/c++/4.9.x/stl/_ostream.h:304:1: note: candidate function [with _Traits = std::char_traits<char>]
operator<<(basic_ostream<char, _Traits>& __os, char __c) {
^
/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../include/c++/4.9.x/stl/_ostream.h:297:1: note: candidate function [with _CharT = char, _Traits = std::char_traits<char>]
operator<<(basic_ostream<_CharT, _Traits>& __os, char __c) {
^
/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../include/c++/4.9.x/stl/_ostream.h:311:1: note: candidate function [with _Traits = std::char_traits<char>]
operator<<(basic_ostream<char, _Traits>& __os, signed char __c) {
^
/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../include/c++/4.9.x/stl/_ostream.h:318:1: note: candidate function [with _Traits = std::char_traits<char>]
operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c) {
^
/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../include/c++/4.9.x/stl/_iomanip.h:96:1: note: candidate function [with _CharT = char, _Traits = std::char_traits<char>]
operator<<(basic_ostream<_CharT, _Traits>& __os,
^

1 个答案:

答案 0 :(得分:2)

_STLP_LONG_LONGSTLPort macro。如果您确实在使用STLPort,则可能需要编辑NDK中的文件stl_mycomp.h

但是,由于STLPort only supports C++98并且从NDK r16开始不推荐使用,因此您应该使用libc ++(在NDK之前,r16 gnustl也可能是一个选项)。

相关问题