Intermittent MacOSX SDK include file not found

On two different Macs I get intermittent errors where SDK include files are not found. The file that contains the include statement, and the included file not found are different most times. When I check for the file it exists.

A rebuild often works.

Xcode 13.1 with MacOSX12.0.sdk and 13.3 with MacOSX12.3.sdk

I've looked in the system console for error around the failure time, but cannot see anything. AFAIK i do not have any automatic updates selected. I checked timestamps of files/folders involved, and none are recent.

Example error:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/algorithm:653:10: 'memory' file not found

#include <memory>

One Mac is Mojave, one is on Monterey. I checked max nr of open files, for both its set reasonably high. Mojave: kern.maxfiles: 12288 kern.maxfilesperproc: 10240 Monterey: kern.maxfiles: 122880 kern.maxfilesperproc: 61440

Intermittent MacOSX SDK include file not found
 
 
Q