Android NDK16 错误("operator '<<' is ambiguous (with operand types 'basic_ostream<char, std::char_traits<char> >' and 'long long')"
Android NDK16 error ("operator '<<' is ambiguous (with operand types 'basic_ostream<char, std::char_traits<char> >' and 'long long')"
在尝试从 NDK 15c 过渡到 NDK16b 时,我遇到了编译遗留代码的障碍,该代码试图将 64 位 long long 值写入 ostream。
我搜索了 NDK 头文件,std/_ostream
在我看来,如果定义了 #ifdef _STLP_LONG_LONG
,那么 ostream 运算符应该支持我正在尝试做的事情。
我看不出我需要做什么才能启用它。我试过用 -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,
^
_STLP_LONG_LONG
是一个 STLPort macro。如果您真的在使用 STLPort,那么您可能需要在 NDK 中编辑文件 stl_mycomp.h
。
但是,由于 STLPort only supports C++98 并从 NDK r16 开始被弃用,您应该改用 libc++(在 NDK r16 之前,gnustl 也可能是一个选项)。
在尝试从 NDK 15c 过渡到 NDK16b 时,我遇到了编译遗留代码的障碍,该代码试图将 64 位 long long 值写入 ostream。
我搜索了 NDK 头文件,std/_ostream
在我看来,如果定义了 #ifdef _STLP_LONG_LONG
,那么 ostream 运算符应该支持我正在尝试做的事情。
我看不出我需要做什么才能启用它。我试过用 -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,
^
_STLP_LONG_LONG
是一个 STLPort macro。如果您真的在使用 STLPort,那么您可能需要在 NDK 中编辑文件 stl_mycomp.h
。
但是,由于 STLPort only supports C++98 并从 NDK r16 开始被弃用,您应该改用 libc++(在 NDK r16 之前,gnustl 也可能是一个选项)。