ERROR: 'xcodebuild' requires Xcode

OBSERVATIONS

I was not expecting the command to return an error:

/usr/bin/xcodebuild -version (Reference) returns an error:

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

ls -l /usr/bin/xcodebuild returns:

-rwxr-xr-x 1 root wheel 31488 May 27 19:37 /usr/bin/xcodebuild

xcodebuild -version returns:

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

gcc --version returns:

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1 Apple clang version 11.0.3 (clang-1103.0.32.62) Target: x86_64-apple-darwin19.5.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin

QUESTIONS

Why is the an error returned in the first observation and what remedies are available?

How can I test (without installing anything to determine if I have the problem described here?

I am concerned that changing the active directory

sudo xcode-select -switch /Library/Developer/CommandLineTools

will cause problems with brew or other installed apps. Though it would seem that my active directory and the suggested change is the same.

UPDATES

$ ls -l /Applications/
total 0
drwxr-xr-x  4 user  admin  128 Jul 26 00:06 Polyspace
drwxr-xr-x@ 3 root  wheel   96 Apr 23 00:52 Safari.app
drwxr-xr-x@ 3 user  staff   96 Sep 30  2019 Sublime Text.app
drwxr-xr-x@ 3 user  staff   96 May 15 20:06 Transmission.app
drwxr-xr-x  4 root  wheel  128 May 27 19:31 Utilities
$ ls /usr/bin | grep -I Xcode
xcode-select
xcodebuild

Solution 1:

Assuming your Xcode.app is installed in /Applications you can just run

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

to fix this.

Solution 2:

Why is the an error returned in the first observation

Because xcodebuild executable in /usr/bin is not useful without Xcode app.

I am concerned that changing the active directory... will cause problems with brew or other installed apps.

No it does not. When Xcode is installed, setting the xcode-select path to Xcode app gives you more features: in particular xcodebuild which is required for making Xcode projects from cmake etc.

The Command Line Tools package installs the macOS system headers inside the macOS SDK. Software that compiles with the installed tools will search for headers within the macOS SDK provided by either Xcode at: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk

or the Command Line Tools at:

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

depending on which is selected using xcode-select. The command line tools will search the SDK for system headers by default.

Source: https://developer.apple.com/documentation/xcode-release-notes/xcode-10-release-notes

So there will not be any problem as long as the tool you're concerned about works with SDK, and is not dependent on unix-like /usr/include paths.

Though it would seem that my active directory and the suggested change is the same.

Whenever in doubt, print it:

xcode-select --print-path
xcode-select -p

Read the man page: man xcode-select for more.