I am running an older version of MacOS and Xcode. In the older version,
the command line tools are installed with the command
sudo xcode-select --install
Also, the switch command that I have always used is
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
The command given in the original post would be appropriate if you have
multiple versions of Xcode installed, and you wanted to switch to a
nondefault version.
Also, before you actually use Xcode, you need to run the command
sudo xcodebuild -license
or you need to click the license agreement within the Xcode app itself.
Otherwise, I think you do get those types of ld errors because of file
permission errors.
However, perhaps some or all of this has changed in the most recent
version of MacOS.
$.02 -Ron Shepard