124

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?

2
  • 3
    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. Commented Dec 20, 2016 at 14:31
  • @rudolf-ratusinski answer still works on Xcode 11.2.1
    – AJC
    Commented Dec 6, 2019 at 14:59

8 Answers 8

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.

9
  • 4
    I got the error xcode-select: error: invalid developer directory '/Applications/Xcode.app/Contents/Developer' Commented Jun 13, 2016 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. Commented Sep 14, 2016 at 14:02
  • 1
    Thanks, with XCode 8 after editing default_pre.prf it works !
    – Libor B.
    Commented Sep 15, 2016 at 5:56
  • 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
    Commented Oct 13, 2016 at 7:12
  • 3
    With homebrew, after installing [email protected] (which is required for the Ruby capybara gem), I found the relevant default_pre.prf file at: /usr/local/Cellar/[email protected]/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. Commented Jan 3, 2017 at 13:14
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.

8
  • 1
    I prefer this version, so it looks less messy than editing cfg files.
    – tjeden
    Commented Sep 26, 2016 at 22:19
  • 3
    This causes problems later when xcrun is invoked with parameters not supported by xcodebuild (missing parameter -f).
    – mrAlmond
    Commented Sep 29, 2016 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 Commented Sep 30, 2016 at 14:26
  • 1
    Don't do this, it mess up my iphone app project.
    – Chchwy
    Commented Nov 7, 2016 at 10:37
  • 1
    I upvoted this too soon and got it locked in... I ran into the parameter -f issue.
    – BuvinJ
    Commented Nov 17, 2016 at 17:14
27

This will do the trick:

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

Run this in your terminal.

4
  • works in Xcode8 and easier than the other steps. Thanks!
    – Misha
    Commented May 17, 2017 at 17:25
  • Confirmed it works on macOS Sierra 10.12.4 with Xcode 8 - Thank you! Commented Jun 8, 2017 at 15:15
  • 1
    This is still working on macOS High Sierra 10.13.5 with Xcode 9.4.1 - Thank you!
    – d1jhoni1b
    Commented Jun 29, 2018 at 3:53
  • Confirmed this works in macOS Catalina 10.15.2 with Xcode 11.3. Commented Jan 2, 2020 at 19:42
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")))
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
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

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

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

1
  • If you are going to neg an answer, at least have the courtesy to give a clue as to why!
    – nerak99
    Commented Apr 22, 2021 at 17:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.