C++:ifstream getline 问题交叉编译到 OpenWRT 发行版中

C++: ifstream getline issue crosscompiling into an OpenWRT distro


我正在尝试在我的自定义 OpenWRT 发行版中编译一个简单的 C++ 代码,但是 getline 指令出现错误。
这是我的代码的快照:

#include <stdio.h>                                                                                                                                                                                                                    
#include <string.h>
#include <unistd.h>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <sys/stat.h>
...

ifstream infile(MODEL);
if (infile.fail())
    return;
getline(infile, model);

...

我收到这种警告(我正在使用 -Werror 标志进行编译)

In file included from /home/nino/workspace/fmrepo/fm-mt762x/buildroot/staging_dir/target-mipsel_1004kc+dsp_uClibc-0.9.33.2/usr/include/uClibc++/iostream:30:0,
                 from fmsnmpwalk.cpp:5:
/home/nino/workspace/fmrepo/fm-mt762x/buildroot/staging_dir/target-mipsel_1004kc+dsp_uClibc-0.9.33.2/usr/include/uClibc++/string_iostream: In instantiation of 'std::basic_istream<charT, traits>& std::getline(std::basic_istream<charT, traits>&, std::basic_string<Ch, Tr, A>&, charT) [with charT = char; traits = std::char_traits<char>; Allocator = std::allocator<char>]':
/home/nino/workspace/fmrepo/fm-mt762x/buildroot/staging_dir/target-mipsel_1004kc+dsp_uClibc-0.9.33.2/usr/include/uClibc++/string_iostream:114:16:   required from 'std::basic_istream<charT, traits>& std::getline(std::basic_istream<charT, traits>&, std::basic_string<Ch, Tr, A>&) [with charT = char; traits = std::char_traits<char>; Allocator = std::allocator<char>]'
fmsnmpwalk.cpp:47:23:   required from here
/home/nino/workspace/fmrepo/fm-mt762x/buildroot/staging_dir/target-mipsel_1004kc+dsp_uClibc-0.9.33.2/usr/include/uClibc++/string_iostream:97:11: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
  for(i=0;i<n;++i){
           ^
cc1plus: all warnings being treated as errors

我不明白这是什么问题。
在我的 OpenWRT 发行版上,我使用 gcc 5.xuClibc-0.9.33.2.
任何帮助表示赞赏。谢谢!

如错误所述:

error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

因此,您在 uClibc++ 的某处(即 std::getline 中有此代码 for(i=0;i<n;++i){,其中 in 具有不同的符号(也许, i 是一个 intn 代表一些长度并且是一个 size_t,它是无符号的)。

您可以使用 -Wno-sign-compare.

之类的内容关闭此警告