123

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?

123
  • 8,733
  • 14
  • 57
  • 99

8 Answers8

279

>= 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.

Ricardo Stuven
  • 4,704
  • 2
  • 34
  • 36
123
  • 8,733
  • 14
  • 57
  • 99
  • 4
    I got the error xcode-select: error: invalid developer directory '/Applications/Xcode.app/Contents/Developer' – Mohammed Rafeeq Jun 13 '16 at 14:33
  • 14
    Doesn't work for me with Xcode 8. I have accepted the license via these instructions and still get the same error. – Violet Giraffe Sep 14 '16 at 14:02
  • 1
    Thanks, with XCode 8 after editing default_pre.prf it works ! – Libor B. Sep 15 '16 at 05:56
  • For the Xcode>=8 segment, if you are building Qt from a source tree, you also need to patch the `configure` file similarly. The commit which fixes this issue in Qt is https://codereview.qt-project.org/gitweb?p=qt/qtbase.git;a=commitdiff;h=77a71c32c9d19b87f79b208929e71282e8d8b5d9 – DLRdave Oct 04 '16 at 09:09
  • 11
    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. – yogodoshi Oct 13 '16 at 07:12
  • I was getting this error when trying to install py35-PyQt5 from macports. The edit to default_pre.prf suggested in this answer fixed the error for me. Note that (as mentioned by yogodoshi above) for macports the file to edit is /opt/local/libexec/qt5/mkspecs/features/mac/default_pre.prf – Steve Dec 09 '16 at 16:02
  • 3
    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. – Ben Hocking Jan 03 '17 at 13:14
  • dont forget to add ': \' at the end – moody Oct 09 '17 at 13:04
  • 1
    @Ricardo Stuven I Opened the file "default_pre.prf" but found that the line is already set correctly. then I tried the `xcode-select -switch` command but I got "invalid developer directory error". – Dev M Jul 11 '18 at 18:21
84

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.

Rudolf Ratusiński
  • 1,087
  • 1
  • 8
  • 8
  • 1
    I prefer this version, so it looks less messy than editing cfg files. – tjeden Sep 26 '16 at 22:19
  • 3
    This causes problems later when xcrun is invoked with parameters not supported by xcodebuild (missing parameter -f). – mrAlmond Sep 29 '16 at 13:15
  • 3
    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 – ALoopingIcon Sep 30 '16 at 14:26
  • 1
    Don't do this, it mess up my iphone app project. – Chchwy Nov 07 '16 at 10:37
  • 1
    I upvoted this too soon and got it locked in... I ran into the parameter -f issue. – BuvinJ Nov 17 '16 at 17:14
  • I didn't read the comments before I ran the commands. How can you undo this? I dont see any issues, but im afraid I will months from now. Not sure how to test if this caused an issue for me. – John Pollard Dec 09 '16 at 01:10
  • 1
    To remove it sudo rm /Applications/Xcode.app/Contents/Developer/usr/bin/xcrun – Daniel Georgiev Dec 09 '16 at 15:04
  • This worked great. There definitely is a missing parameter -f problem, but I couldn't get .prf changes to stick, so going to just deal with it for now. – ahay Mar 06 '17 at 00:05
27

This will do the trick:

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

Run this in your terminal.

Shnd
  • 1,846
  • 19
  • 35
12

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")))
Honest Abe
  • 8,430
  • 4
  • 49
  • 64
Bruce
  • 171
  • 1
  • 5
5

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
remikz
  • 438
  • 6
  • 4
3

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

Ramses
  • 996
  • 4
  • 12
  • 28
1

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

Marcelo
  • 11
  • 1
-2

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).

nerak99
  • 640
  • 8
  • 26