MATLAB: Do I get xcrun error SDK “macosx10.13.4” cannot be located when using loadlibrary

activeappleapplicationbrewcommandcompilationcompilercontentsdeveloperdirectoryfailurehomebrewlinemacMATLABmexosxterminaltoolsxcodexcode.app

Why do I get following error when using loadlibrary on MacOS?
[~,warnings] = loadlibrary(libpath, headerpath, 'alias', 'libbf2');
Warning: Message from C preprocessor:
xcrun: error: SDK "macosx10.13.4" cannot be located
> In loadlibrary
and
>> warnings
warnings =
'xcrun: error: SDK "macosx10.13.4" cannot be located
Type 'char__signed' was not found. Defaulting to type error.
Found on line 15 of input from line 30 of file /Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk/usr/include/sys/_types/_int8_t.h
Failed to parse type 'union { char *__mbstate8; long long _mbstateL ; } __mbstate_t' original input 'union { char __mbstate8 [ 128 ]; long long _mbstateL ; } __mbstate_t'
Found on line 110 of input from line 79 of file /Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk/usr/include/i386/_types.h
Type '__mbstate_t' was not found. Defaulting to type error.
Found on line 112 of input from line 81 of file /Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk/usr/include/i386/_types.h
xcrun: error: SDK "macosx10.13.4" cannot be located
'

Best Answer

The user may need to reset their active developer directory path:
Check their active developer directory path by running "xcode-select -p" in their MacOS terminal:
xcode-select -p
/Library/Developer/CommandLineTools
They can reset their active developer directory to the default command line tools path with "xcode-select -r":
sudo xcode-select -r
xcode-select -p
/Applications/Xcode.app/Contents/Developer