c++ifstreamgetlineopenwrtuclibc

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



I'm trying to compile a simple C++ code inside my customized OpenWRT distro, but I have an error with the getline instruction.
Here it is a snapshot of my code:

#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);

...

I receive this kind of warning (I am compiling with -Werror flag)

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

I can't understand what is the problem.
On my OpenWRT distro I am using gcc 5.x and uClibc-0.9.33.2.
Any help is appreciated. Thanks!


Solution

  • As the error says:

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

    So, you have this code for(i=0;i<n;++i){ somewhere in your uClibc++ (namely, in std::getline), where i and n are of different signs (perhaps, i is an int while n represents some length and is a size_t, which is unsigned).

    You can just turn this warning off with something like -Wno-sign-compare.