简体   繁体   English

Qt MacOS - 正确的工作目录?

[英]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. 我之前从未使用过Mac,但我正在使用Qt 5.6.2在MacOS 10.12.5上构建一些Qt应用程序。 When I ran the application from Qt Creator I got the error: 当我从Qt Creator运行应用程序时,我收到了错误:

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. 经过一番调查后,我发现问题似乎与Qt Creator项目设置中的工作目录有关。 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: Qt Creator会将工作目录设置为:

/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. 我发现如果你将工作目录更改为与build目录相同(就像在Windows中一样),这可以解决问题,因此程序将运行并调试而不会出现问题。 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. 但是,由于我是Mac新手,我担心这是错误的做法,可能会为测试创造一个不适当的环境。

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? 为什么Qt Creator在导致应用程序无法运行时将/MyApp.app/Contents/MacOS附加到工作目录?

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: 默认情况下,Qt Creator将此目录结构用于构建:

[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: 这看起来很傻,所以我从默认的构建目录中删除了-%{CurrentBuild:Name} ,这使得目录结构更加合理:

[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: 在Linux上,默认情况下不会创建调试和发布子目录,因此要在同一个构建目录结构中工作,我必须将以下行添加到我的.pro文件中:

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. 当我在Mac上构建时,似乎这些设置引起了很多问题。 Running and debugging the program didn't work and the icon wasn't being set ( ICON = myicon.icns wasn't working). 运行和调试程序不起作用,图标未设置( ICON = myicon.icns无效)。 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. 恢复到默认的构建目录(最后使用-%{CurrentBuild:Name} )并从我的.pro文件中删除该行解决了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. 我无法忍受这样的事实:-debug / release和-release / debug目录完全是冗余的并且总是空的。 Unfortunately changing the settings ended up making things worse. 不幸的是,更改设置最终会使事情变得更糟。 I'm going out for chocolate... 我要外出吃巧克力......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM