-1


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!

neoben
  • 743
  • 12
  • 30
  • 1
    You haven't shown the offending code but I assume you have a variable `n` which is of type `unsigned int` or `std::size_t` which would cause this comparison warning. – sjrowlinson Jun 16 '16 at 16:42
  • The warning is for a for loop that is not in the snapshot of your code... – Borgleader Jun 16 '16 at 16:43

1 Answers1

1

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.

ForceBru
  • 43,482
  • 10
  • 63
  • 98