'VS Code C Error - Invalid Active Developer Path

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

This is the error I get in VS Code's terminal. There are error squiggles under the "#include <stdio.h>" line.

This is after I upgraded to Mac OS Monterey.

What is the reason for this error and what is the solution?



Solution 1:[1]

When upgrading your Mac OS, sometimes the code command-line tools stop working. This can be resolved by running this in the terminal:

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

If you don't have Xcode installed you should do:

xcode-select --install

which will install the command-line tools without having Xcode.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1