Score:0

gcc compiler can't find include file stdio.h

rw flag

The gcc compiler can't find the include file stdio.h.

$ batcat test.c
───────┬──────────────────────────────────────────────────────────
       │ File: test.c
───────┼──────────────────────────────────────────────────────────
   1   │ #include <stdio.h>
   2   │ int main(void){
   3   │     printf("hello world");
   4   │     return 0;
   5   │ }

$ gcc test.c
In file included from test.c:1:
/usr/local/include/stdio.h:6:10: fatal error: sys/stdio.h: No such file or directory
    6 | #include <sys/stdio.h>
      |          ^~~~~~~~~~~~~
compilation terminated.

as you can see below, the stdio.h file is present in the /usr/local/include directory.

/usr/local/include  via  v11.3.0-gcc
$ ls
assert.h  float.h     locale.h  stdarg.h   stdio.h   wchar.h
bits      inttypes.h  math.h    stdbool.h  stdlib.h  wctype.h
ctype.h   iso646.h    setjmp.h  stddef.h   string.h
errno.h   limits.h    signal.h  stdint.h   time.h

I have tried reinstalling gcc, libc6, libc6-dev as well.

hr flag
Packages from the Ubuntu repositories normally don't install files in /usr/local - normally, gcc would resolve `#include <stdio.h>` as `/usr/include/stdio.h` for example. Have you manually installed standard library files to /usr/local?
Hannu avatar
ca flag
I'm not a developer nor specially knowledgeable about gcc, but I do believe that installation of complex software (e.g. gcc) is best done via 'standard means'. For ubuntu that is starting with `sudo apt install build-essentials` and then possibly by adding other *.deb packages from the same or related repositories. Ubuntu 20.04 has gcc 9.4, later releases might have newer versions, but most likely still with stdio.h placed in /usr/include/stdio.h - so the impression is that you have used some other means to get your gcc installed, and failed to get it done correctly.
hr flag
@Hannu even if gcc is correctly installed from the Ubuntu repo, it will search /usr/local/include before /usr/include I think (you can display the built-in search paths with `: | gcc -v -E -xc -` for example)
Anup avatar
rw flag
@steeldriver you were right. include files should not be in /usr/local for gcc. I was trying to install another compiler which messed up the gcc. rm -rf /usr/local/include helped in resolving it. Thanks!
Score:3
ca flag

The reason that triggered this problem was installing an alternative compiler called scc from source. It seems that this somehow conflicted with runtime paths for gcc.

My initial impression from the discussions in the comments was that the include files for gcc should not be in /usr/local/include directory but the documentation does say that gcc checks this directory for include files. So I'm not sure what was the problem.

I deleted this folder entirely and that resolved the issue for me:

rm -rf /usr/local/include/

Answer moved here from OP's question.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.