Catalina: no luck with CmdLineTools –> fatal error: stdio.h: No such file or directory

So now that I’ve been able to get many of my old Linux apps to work again in the brave new 64bit world that is Catalina I wrestle with compiling my own code. I have gcc through homebrew, but so far I haven’t run into anything fatal with clang and what Apple provides through the CommandLineTools via xcode-select --install.

But when I compile one of my C++ projects that I was able to compile just fine on Mojave I’m now faced with

% make
g++ -DHAVE_CONFIG_H -I. -I… -I/Users/simon/…/tricia/inc -I/Users/simon/…/inc -g -O0 -Wall -Wno-non-template-friend -g -O2 -MT m4.o -MD -MP -MF .deps/m4.Tpo -c -o m4.o m4.cc
In file included from m4.cc:3:0:
/Users/simon/…/tricia/inc/tricia_lib.h:11:10: fatal error: stdio.h: No such file or directory
#include <stdio.h>
^~~~~~~~~
compilation terminated.
make: *** [m4.o] Error 1

Sure enough, there’s no /usr/include/ anymore in Catalina. I was able to find all the goodies in
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include
but Catalina won’t even allow sudo ln -s of that onto /usr/include.

Any idea how to get my compiler to pick up all the libraries in this unusual location?

Will the compiler automatically look in /usr/local/include/? You can make a directory or symlink there. If it doesn’t already look there for libraries, I would think you could make it do so by changing an environment variable or passing a parameter to the compiler.

Thank you, @cwilcox.

I’m not sure I understand. My /usr/local/include does not contain stdio.h. That’s in the Command Line Tools directory I posted above.

I’ll see if I can pass that directory explicitly to the compiler. To be honest, I’ve never had to do so before myself (/usr/include existed for me up to Mojave) so I’ll have to find out how and where first.

Just a suggestion…
For error messages like that, with any language, any compiler, any runtime environment, I used to find a solution by pasting it into Google. Up would pop a discussion on stackexchange that explained the issue and how to solve it.
That has mostly worked for me.

There’s nothing in my /usr/local/include/ so if yours is the same, I was thinking you could remove it and replace it with symlink to the directory within /CommandLineTools/. Alternately, symlink all the files within the source folder in the destination folder:

sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/* /usr/local/include/

I think /usr/local/include/ is likely in the the compiler’s library path already but if not, you’ll still need to add it.

That header should be distributed with your C compiler. What are you using? If you’re using Xcode, is it properly installed? If not, what are you using and is it properly installed?

That’s good advice and actually one of the first things I did. Turns out all the discussions I was able to find on stackexchange were related to Mojave and the old CommandLineTools installer. Back then you were still able to launch an installer and it would populate /usr/include. But in the brave new Catalina world, that directory is verboten.

Thanks, @cwilcox. My /usr/local/include is actually full of stuff. I guess mostly courtesy of brew. I think you’re right though, symlinking into that directory should work, if…

I’m actually not sure about that. If I need to add it to the compiler’s path I guess I might as well just put the Catalina CLTools includes into its path and be done with it. That’ll be next.

I’m actually using both Apple’s (clang), but I also have gcc-9 through brew. I switched back and forth between the two, but both failed at exactly the same point complaining about missing stdio.h. In the case of gcc probably not surprisingly considering Apple removed /usr/include. In the case of clang I’m a bit more surprised. Maybe something else is screwed up here, can’t really tell. But the CLTools installer had no complaints as was the case for a forced reinstall. Oh well. If I can force my compiler to pick up the CLTools includes it should work. Just need to figure out the right edits for my various old make files.