ChatGPT解决这个技术问题 Extra ChatGPT

Qt Creator - Project ERROR: Xcode not set up properly. You may need to confirm the license agreement by running /usr/bin/xcodebuild

I just installed Qt 5.5 and am using Qt Creator for the first time on OS X. When I first installed Qt, it gave me an error message 'Xcode 5 not installed' which I thought was strange, (I have the Xcode 7 beta), but the install completed successfully anyways.

Now, when I start or open a project, I get the error:

Project ERROR: Xcode not set up properly. You may need to confirm the license agreement by running /usr/bin/xcodebuild.

When I run /usr/bin/xcodebuild in Terminal, I get the following:

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

I'm not sure what Xcode has to do with Qt Creator, unless it has something to do with accessing libraries for cross-platform compatibility, but is there a way to fix this issue?

Note: For Qt 5.7.1 and Xcode 8.2.1 the answer by @rudolf-ratusinski however does the job perfectly. Accepted answer does not work.
@rudolf-ratusinski answer still works on Xcode 11.2.1

R
Ricardo Stuven

>= Xcode 8

In Xcode 8, as Bruce said, this happens when Qt tries to find xcrun when it should be looking for xcodebuild.

Open the file:

Qt_install_folder/5.7/clang_64/mkspecs/features/mac/default_pre.prf

Replace:

isEmpty($$list($$system("/usr/bin/xcrun -find xcrun 2>/dev/null")))

With:

isEmpty($$list($$system("/usr/bin/xcrun -find xcodebuild 2>/dev/null")))

~> Xcode 8

Before Xcode 8, this problem occurs when command line tools are installed after Xcode is installed. What happens is the Xcode-select developer directory gets pointed to /Library/Developer/CommandLineTools.

Point Xcode-select to the correct Xcode Developer directory with the command:

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

Confirm the license agreement with the command:

sudo xcodebuild -license

This will prompt you to read through the license agreement.

Enter agree to accept the terms.


I got the error xcode-select: error: invalid developer directory '/Applications/Xcode.app/Contents/Developer'
Doesn't work for me with Xcode 8. I have accepted the license via these instructions and still get the same error.
Thanks, with XCode 8 after editing default_pre.prf it works !
For those wondering where is the installation folder: it will depend on your package manager's settings: /usr/local/Cellar/qt55 for Homebrew, /opt/local/libexec/qt5(-mac) for macports.
With homebrew, after installing qt@5.5 (which is required for the Ruby capybara gem), I found the relevant default_pre.prf file at: /usr/local/Cellar/qt@5.5/5.5.1/mkspecs/features/mac/default_pre.prf. I also tried Rudolf Ratusiński's approach, and while it got me over the first hump, it resulted in numerous spurious messages later that I did not get when I used this approach instead.
R
Rudolf Ratusiński

If you change content of Qt_install_folder/5.7/clang_64/mkspecs/features/mac/default_pre.prf then it will work only for Desktop kit, not for ex. simulator.

A better way is just to create symlink:

cd /Applications/Xcode.app/Contents/Developer/usr/bin/
sudo ln -s xcodebuild xcrun

so you don't have to change .prf files for all targets.


I prefer this version, so it looks less messy than editing cfg files.
This causes problems later when xcrun is invoked with parameters not supported by xcodebuild (missing parameter -f).
It seems a qt issue. So I consider more dangerous adding a lasting sym link inside xcode distrib than changing a qt conf file that will be replaced by Qt 5.7.1
Don't do this, it mess up my iphone app project.
I upvoted this too soon and got it locked in... I ran into the parameter -f issue.
S
Shnd

This will do the trick:

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

Run this in your terminal.


works in Xcode8 and easier than the other steps. Thanks!
Confirmed it works on macOS Sierra 10.12.4 with Xcode 8 - Thank you!
This is still working on macOS High Sierra 10.13.5 with Xcode 9.4.1 - Thank you!
Confirmed this works in macOS Catalina 10.15.2 with Xcode 11.3.
H
Honest Abe

For users of Xcode 8, there is another problem. See here for a temporary solution until Qt 5.7.1 is released:

https://forum.qt.io/topic/71119/project-error-xcode-not-set-up-properly

To summarise:

Open Qt_install_folder/5.7/clang_64/mkspecs/features/mac/default_pre.prf in a text editor, and replace this:

isEmpty($$list($$system("/usr/bin/xcrun -find xcrun 2>/dev/null"))))

with this:

isEmpty($$list($$system("/usr/bin/xcrun -find xcodebuild 2>/dev/null")))

r
remikz

If you build Qt from source with XCode 8.x, you have to change the "-find" argument in the file qt-everywhere-enterprise-src-5.7.0/qtbase/configure on line 551 so that it looks like:

if ! /usr/bin/xcrun -find xcodebuild >/dev/null 2>&1; then

R
Ramses

Managed to solve it installing the full version of Xcode, agreeing to the terms, then using xcode-select --reset.

Basically the problem is that the xcode you're pointing at /Library/Developer/CommandLineTools doesn't allow you to accept the terms & conditions. So after the install & resetting the location, all should be OK


M
Marcelo

For me, the only way to work correctly is to commenting the lines about xcrun with the '#':

# Make sure Xcode is set up properly
#isEmpty($$list($$system("/usr/bin/xcrun -find xcrun 2>/dev/null"))): \
    #error("Xcode not set up properly. You may need to confirm the license agreement by running /usr/bin/xcodebuild.")

At the file: Qt_install_folder/5.7/clang_64/mkspecs/features/mac/default_pre.prf


n
nerak99

Just to add a bit to a lot of old answers in the spirit of "This worked for me" I found that by launching Xcode, logging in to my developer account (just a free one) and then setting the Command tools in "Locations". I could get the

'sudo /usr/bin/xcodebuild -license agree'

to work. i.e. it launched an agree process in the command line and I agreed after careful reading of all 14 squillion pages of stuff.

I did not have to edit anything.

My system is Mojave 10.14.6 and Xcode 10.3 (10G8).


If you are going to neg an answer, at least have the courtesy to give a clue as to why!