7

As the title suggests I'm experiencing a rather odd problem. When I try to compile a sample source code (that uses libotb) I keep getting errors like the one in the title. What is weird is that #include <iostream> is present in the said source/header where the error is reported.

On the other hand if I extract the code from the said file and create a separate source and compile it with g++ <source_file> it works, but if I compile with g++ -I<path_to_libotb_headers> <source_file> I get the same error, although the source file doesn't include anything from said path.

As stated in the below comments, this issue happens with simply

#include <iostream>   

int main                                                                                
{
    std::cerr << "Test";
    return 0;
}
skyel
  • 713
  • 1
  • 6
  • 20
  • So what is the question? Some code we haven't seen contains an error. There's not much we can do about that – jalf Nov 20 '12 at 10:35
  • did you use `using namespace std` or `std::` prefixes? – Dmytro Sirenko Nov 20 '12 at 10:36
  • @jalf: Does the code have any relevance? – skyel Nov 20 '12 at 10:36
  • @EarlGray: I've reduced it to `#include int main() { std::cerr << "Test"; return 0; } ` – skyel Nov 20 '12 at 10:37
  • 1
    This answer might be useful to verify that you actually included the intended headers when changing the include-path (g++ -H) http://stackoverflow.com/a/6685693/104774 – stefaanv Nov 20 '12 at 10:54
  • look at "" and see what headers are in there - I agree with stefaanv that examining what the includes used actaully are is your best way forward... – Caribou Nov 20 '12 at 11:05
  • 1
    Does maybe `path_to_libotb_headers` lead to a header called `iostream` so that one gets picked up? – Daniel Fischer Nov 20 '12 at 12:26
  • @DanielFischer: for some odd reason it seems that there was indeed a file called iostream, but it didn't cross my mind and due to the fact that there were almost 2k files in that folder I didn't spot it – skyel Nov 20 '12 at 14:48
  • Add `-H` to gcc or g++ arguments to print out paths to all used header files. Look through the listing to spot obvious problems, like `iostream` not in the standard path. – n. m. could be an AI Oct 14 '14 at 17:32

4 Answers4

8
#include <ostream>

should fix it. Under C++11, #include <iostream> is supposed to pull in all of <ostream>, but prior to C++11 you had to do the individual #includes.

Pete Becker
  • 74,985
  • 8
  • 76
  • 165
3

It should be:

int main ()

  • you missed the () :)
Luke
  • 39
  • 1
1

Verify that your includes all closed their namespaces -- your include may accidentally be declared in a namespace if a previous header did not close its namespaces.

You can also attempt to locate this problem by moving the std includes earlier in the include list.

justin
  • 104,054
  • 14
  • 179
  • 226
0

If you are an Arduino programmer don't forget that Arduino does NOT have any normal ‘ostream’ stuff build-in.
But there is libraries offering similar functions.

PS. Bear in mind that there is good reasons that streaming type stuff is not included.

m2mm4m
  • 1
  • 1