Search code examples
gcccygwin

Cygwin gcc cannot find stdio.h


I have a 64 bit Cygwin on my 64 bit Win7.
I installed gcc-core and gcc-g++ packages.
I made a simple C program:

#include <stdio.h>
int main() {
  exit(0);
}

when I compile with: gcc-c test.c I got:
fatal error: stdio.h: No such file or directory

Doing it with -v flag I see:

#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/include
 /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/include-fixed
 /usr/include
 /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../lib/../include/w32api
End of search list.
GNU C (GCC) version 4.8.3 (x86_64-pc-cygwin) 

The stdio.h which comes with gcc-core package is present on my pc at this location (which is fine according to Cygwin's package searcher also):
/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/include/ssp/stdio.h

What it means that ssp directory and why stdio.h is placed there ?
Why gcc cannot find stdio.h present at this location ?


Solution

  • The file you found in the ssp directory is not a version of <stdio.h>. It only contains extra information about some of the functions in <stdio.h> for the stack-smash protector feature in gcc.

    The actual <stdio.h> should be in /usr/include.

    This line in your -v output is very interesting:

    /usr/inlude
    

    How did you get a /usr/inlude with no c?

    Oops, the missing c in inlude was deleted in the edit by Keith Thompson.

    So your gcc should be finding /usr/include/stdio.h if you have it. Is it there? As far as I can tell from the package file lists, it's supposed to be part of the cygwin base system (i.e. even if you haven't installed the compiler it should be there).

    Are you missing any other header files? <stdlib.h> and <string.h> are good test candidates.

    Here are some commands to investigate the cygwin package and whether it contains the file:

    cygcheck -f /usr/include/stdio.h
    cygcheck -c cygwin
    cygcheck -l cygwin | grep stdio
    

    UPDATE: so it seems I'm behind the times and there's a cygwin-devel package now. The header files aren't in the base cygwin package any more. To check the correct package on the latest cygwin, you'd use

    cygcheck -c cygwin-devel
    

    as has already been done in the comments. And since it's listed as "incomplete" the solution is probably to reinstall it using cygwin's setup program.