3

I have a very simple program:

// hello.cpp
#include <iostream>

using namespace std;

int main() {
   cout << "Hello, world!" << endl;
   return 0;
}

When I used Command Prompt (Windows) and type:

g++ -o hello hello.cpp

I got this error:

In file included from /usr/include/wchar.h:6:0,
                 from /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/include/c++/cwchar:44,

                 from /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/include/c++/bits/posty pes.h:40,
                 from /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/include/c++/iosfwd:40,

                 from /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/include/c++/ios:38,
                 from /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/include/c++/ostream:38 ,
                 from /usr/lib/gcc/x86_64-pc-cygwin/4.9.2/include/c++/iostream:3 9,
                 from hello.cpp:2: /usr/include/sys/reent.h:14:20: fatal error: stddef.h: No such file or directory

 #include <stddef.h>
                    ^ compilation terminated.

Can anyone solve this problem? I try gcc and everything works fine. It seems that g++ is having some problems. My g++ version is 4.9.2

jxh
  • 69,070
  • 8
  • 110
  • 193
pexea12
  • 1,069
  • 2
  • 18
  • 36
  • I think this problem indicates a version mismatch between gcc and g++. Can you verify that they are both the same version? – rici Aug 31 '15 at 17:03
  • Your cygwin installation looks broken –  Aug 31 '15 at 17:03
  • my gcc version is 4.9.3. Do they have to be in the same version ? – pexea12 Aug 31 '15 at 17:04
  • 1
    This might help: http://stackoverflow.com/questions/19642787/netbeans-and-c-installation – Alan Stokes Aug 31 '15 at 17:05
  • Thank you, I will try to reinstall g++ and gcc again. – pexea12 Aug 31 '15 at 17:07
  • There's an exact dupe with no answers at http://stackoverflow.com/questions/31600600/c-g-compilation-error-stddef-h-no-such-file-or-directory and I can't seem to find another dupe with a good answer. – Mark B Aug 31 '15 at 17:12

1 Answers1

2

I hope you are working on Linux.

Try installing build-essentials like

sudo apt-get install build-essential

Even if it did not work then you may have to install libc6-dev.

Swapnil
  • 1,424
  • 2
  • 19
  • 30