Thanks for everyone’s suggestions. After hours searching Google somebody recommended trying the command:
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
It seemed to fix things (I think the SDK path was wrong?) although I’m getting some deprecation errors, but at least it works!