Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / QT

Installing Qt on Mac OS X

4.65/5 (6 votes)
18 Oct 2014CPOL3 min read 66.5K  
A brief guide on what you need to do to get the Qt Creator to compile and develop Qt Applications on Mac OS X without running into install_name_tool_failed

Introduction

Installing Qt is (usually) an easy task: Download the installer, let it do its duty and done you are. This is certainly applicable if you want your Qt IDE to run on Windows, but when it comes to OS X you are very likely to run into the installer error clang install_name_tool failed. I want to explain what clang is, and why its absence (yes, that error message shall indicate its absence - I was surprised too!) causes the installation to fail. I needed quite a bit of time and a hint from a colleague to find out what was wrong, and since not everyone has the luck of having a colleague who happens to know the answer to most of the problems Qt offers you, I decided to share the solution to the mysterious error clang install_name_tool failed error - Which is as easy as big the surprise is when the error hits you for the first time.

Background - What gets installed?

The setup installs the Qt Creator and the Qt binaries. In addition to that they attempt to configure clang, a C++ compiler, and a failed configuration attempt leads to the already mentioned error message. If that error occurs, you can still run Qt based apps on your Mac and the Qt Creator will still start as nothing happened. The trouble starts when you try to compile your code: It won't, because Qt uses clang via the Xcode Command Line Tools.

Fixing the Issue

After a lot of research and talking to a coworker who happens to be some sort of a Qt Guru I eventually found out the problem: Qt access clang via the Command Line Tools, and these tools are not shipped with every version of Xcode. What surprised me the most is that this is nowhere mentioned if you look at the Qt download page - Not a single word, even though many developers will stumble upon the sane issue. Whatsoever, installing the Command Line Tools is fairly easy if you are already familiar with Xcode, and for those who are new to Xcode it is not that big kind of a deal, either.
Start Xcode - Make sure that you have installed the latest and greatest version, and applied all the updates:
Image 1

Open the preferences. You can find them in the Xcode status bar, under Xcode -> Preferences.

Image 2

Select the tab Downloads -> Components. You can see an item Command Line Tools in the List. Click on Install and Xcode starts downloading and installing the Command Line Tools.

Image 3

After the installation has completed you can install Qt flawlessly with the corresponding installer.

Fixing Xcode is not installed in /Developer/Xcode.app/Contents/Developer

Those who never had Qt installed before most likely encounter the error Xcode is not installed in /Developer/Xcode.app/Contents/Developer when trying to build a project - The solution is easy to find, but added here for completeness. The error has historical roots - Qt still tries to access Xcode in the path /Developer/Xcode.app/Contents/Developer - but Apple has moved the installation to /Applications/Xcode.app/Contents/Developer. I can only guess why they did that, suspecting that the intend was to have Xcode in the location where it belongs: It's and application, so it shall be accessible under /Applications. Enough talking, enter the following command in the Terminal and the error shall be a thing from the past:

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

This behavior is documented as a bug of Qt 5.2 - Details can be found in the Qt Bug 31878 description.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)