Search code examples
c++macosqtmacos-sierra

Qt MacOS - Correct Working Directory?


I've never used a Mac before, but I'm building some Qt applications on MacOS 10.12.5 with Qt 5.6.2. When I ran the application from Qt Creator I got the error:

Failed to start program. Path or permissions wrong?

And If I tried to debug I got the error:

Unable to start LLDB "/Applications/Xcode.app/Contents/Developer/usr/bin/lldb": No such file or directory

After some investigation I found the issue appeared to be with the working directory in the Qt Creator project settings. If you build directory is:

/Users/username/dev/build-MyApp-Desktop_Qt_5_6_2_clang_64bit-Debug

Qt Creator will set the working directory to:

/Users/username/dev/build-MyApp-Desktop_Qt_5_6_2_clang_64bit-Debug/MyApp.app/Contents/MacOS

I found that if you change the working directory to be the same as the build directory (as it is in Windows) this resolves the problem, so the program will run and debug without issues. However, since I'm new to the Mac, I'm worried that this is the wrong thing to do and may create an inappropriate environment for testing.

Is changing the working directory to be the same as the build directory the best solution to this problem, or is there a better solution?

Why is Qt Creator appending /MyApp.app/Contents/MacOS to the working directory when it causes the application not to run?


Solution

  • I found the source of the issue and it wasn't anything to do with the working directory, but was related to other settings I had changed. It's unlikely anyone else will have this issue, but I'll explain. By default Qt Creator uses this directory structure for the builds:

    [Build-Directory]-debug/debug - debug build goes here
    [Build-Directory]-debug/release - always empty
    [Build-Directory]-release/debug - always empty
    [Build-Directory]-release/release - release build goes here
    

    This seemed silly, so I removed the -%{CurrentBuild:Name} from the default build directory, which made the directory structure more sensible:

    [Build-Directory]/debug - debug build goes here
    [Build-Directory]/release - release build goes here
    

    On Linux the debug and release sub-directories aren't created by default, so to get the same build directory structure working there I had to add the below line to my .pro file:

    CONFIG += debug_and_release debug_and_release_target
    

    When I came to build on the Mac it seems these settings caused a lot of issues. Running and debugging the program didn't work and the icon wasn't being set (ICON = myicon.icns wasn't working). Reverting to the default build directory (with -%{CurrentBuild:Name} at the end) and removing the line from my .pro file resolved the problems on the Mac.

    My autism really cost me a lot of time there. I just couldn't stand the fact that there were -debug/release and -release/debug directories that were entirely redundant and always empty. Unfortunately changing the settings ended up making things worse. I'm going out for chocolate...