stdio.h Not Found – Fixing ‘stdio.h’ File Not Found Error in GCC

gcc

When I compile a package, I got the following error:

$ make
clang -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -O2  -I/usr/local/include/scws  -I. -I./ -I/usr/local/Cellar/postgresql/11.3/include/server -I/usr/local/Cellar/postgresql/11.3/include/internal -I/usr/local/Cellar/icu4c/64.2/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I/usr/local/opt/openssl/include -I/usr/local/opt/readline/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/libxml2   -c -o zhparser.o zhparser.c
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk' [-Wmissing-sysroot]
In file included from zhparser.c:10:
In file included from /usr/local/Cellar/postgresql/11.3/include/server/postgres.h:46:
/usr/local/Cellar/postgresql/11.3/include/server/c.h:59:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^~~~~~~~~
1 error generated.

When I search this error online, all the online problems are not having header files at /usr/include/. But when I check the directory, it has many header files

$ ls -l /usr/include/stdio.h
-r--r--r--  1 root  wheel  16319 Jan 22  2018 /usr/include/stdio.h

$ ls -l /usr/include/ | wc -l
     266

So, what can I do in my case?

Thanks a lot.

Edited: I updated the error output. I just found out it had a warning too: clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk', But I have MacOSX10.13.sdk instead because I am running MacOSX10.13. I have no ideas why it's looking for 10.14 sdk and not sure if this is the root cause or not.

Best Answer

The root cause of the error message is from the warning message:

clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk'

By checking SDKs directory:

$ cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
$ ls
MacOSX.sdk/      MacOSX10.13.sdk

So, to workaround the problem, it's either re-install xcode suggested by @Mark or create a symbolic link like the following:

$ sudo ln -s MacOSX.sdk/ MacOSX10.14.sdk