通过CMake构建的ios上Qt应用程序的运行时错误 [英] Run-time error for Qt application on ios built via CMake

查看:261
本文介绍了通过CMake构建的ios上Qt应用程序的运行时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨stackoverflowers:)

Hi stackoverflowers :)

如果我构建了一个Qt / qmake示例项目(在我的例子中是模拟时钟示例)并将其部署到运行iOS 7.1的设备上一切顺利:应用程序执行完美在设备上。 Chapeau - 来自digia的人们做了一项艰巨的工作,将ios工具链整合到他们的Qt工作流程中。

If I build a Qt/qmake sample project (in my case the "analog clock" example) and deploy it to a device running iOS 7.1 everything goes smooth: the app executes flawlessly on the device. Chapeau - the folks from digia did a formidable job to integrate the ios toolchain into their Qt workflow.

但是,如果我将qmake项目翻译成CMake项目,那么再也不顺利了。我已经附加了Qt-5.3.1版本的模拟时钟示例(见下文),其中我添加了一个CMakeLists.txt和一个运行CMake的脚本来生成iOS的XCode项目。该项目编译甚至链接(我不得不添加一些额外的链接库,请参阅CMake源文件)。是的。

However, if I translate the qmake project into a CMake project, things don't go that smooth anymore. I've attached the analog clock example from the Qt-5.3.1 release (see below) where I added a CMakeLists.txt and a script that runs CMake to generate an XCode project for iOS. The project compiles and even links (I had to add some additional link libraries, see CMake source file). Yay.

但这里有陷阱:应用程序在运行时崩溃并出现以下错误消息:

But here's the trap: The app crashes at run-time with the following error message:


错误:无法加载平台插件ios

Error: Failed to load platform plugin "ios"

作为这个线程声明必须通过项目设置强制加载libqios。这样做并没有改善这种情况,它只是将错误消息更改为:

As a comment in this thread states one has to "force load" libqios via the project settings. Doing this didn't improve the situation much, it only changed the error message to:


错误:您在调用UIApplicationMain之前创建了QApplication。
如果您正在编写本机iOS应用程序,并且只想将Qt用于应用程序的
部分,那么创建QApplication的好地方是来自UIApplication委托内的
'applicationDidFinishLaunching'。

Error: You are creating QApplication before calling UIApplicationMain. If you are writing a native iOS application, and only want to use Qt for parts of the application, a good place to create QApplication is from within 'applicationDidFinishLaunching' inside your UIApplication delegate.

我有两个问题:


  • 有没有人知道运行时错误的问题是什么?我知道qmake(和相应的ios mkspecs)做了很多魔术。但是如何将其转换为CMake?

  • 为什么我必须手动将几个库(harfbuzzng,qios,libpng和几个iOS框架)链接到我的目标?不应该find_package(Qt5 ...)为我做这个工作?

这里是包含我的Qt-CMake项目的zip文件的链接。我正在使用的Qt版本是适用于iOS的Qt-5.3.1。

Here is the link to a zip file containing my Qt-CMake project. The Qt version I'm using is Qt-5.3.1 for iOS.

编辑:我发现qmake示例没有如果你把它从Qt示例文件夹结构中删除,就像这样工作。直接查看Qt示例:path / to / Qt / examples / widgets / widgets / analogclock。

Edit: I found out that the qmake sample doesn't work just like this if you tear it out of the Qt examples folder structure. Look at the Qt example directly: path/to/Qt/examples/widgets/widgets/analogclock.

推荐答案

经过几个小时的挖掘后,我发现了一种如何为我的Qt应用程序创建一个CMake项目的方法。我通过Google获得的关键提示以及检查qmake生成的输出。我找到了实际完成魔术的脚本,并将它的一部分应用到我的CMake源。

After a few hours of digging around I found a way how to create a CMake project for my Qt application for iOS. The key hints I got via Google and by checking the output generated by qmake. I found the scripts that actually do the whole magic and applied parts of it to my CMake sources.

这是对我有用的配方。为了完整起见,我还添加了我在发布上述问题时已经知道的步骤:

This is the recipe that worked for me. For the sake of completeness, I added also the steps that I was already aware of when I posted above question:


  • 介绍CMake到ios工具链。查看我的示例项目的cmake / toolchain / ios.toolchain.cmake。它设置了几个CMake属性,并寻找必要的工具和框架。 (我不记得我从哪里获得该文件了 - 但是如果你谷歌的话,它也被用在其他几个项目中。)你必须将这个设置文件作为参数传递给CMake(见下文)。

  • Introduce CMake to the ios tool chain. See cmake/toolchain/ios.toolchain.cmake of my sample project. It sets several CMake properties and looks for the necessary tools and frameworks. (I don't recall anymore where I have that file from - but it is used in several other projects too if you Google for it.) You have to pass this setup file as an argument to CMake (see below).

设置可执行文件的多个目标属性,将其转换为(iOS)应用程序包。应该清楚。请注意,有一个模板Info.plist.in将由CMake完成。

Set several target properties of your executable to turn it into an (iOS) app bundle. Should be clear. Note that there's a template Info.plist.in that will be completed by CMake.

修复1 :链接缺少的库和框架在CMake手动应用程序。出于某种原因, find_package(Qt5 ...)不会返回完整的依赖项列表。很可能我在这里遗漏了一些东西。

Fix 1: Link missing libraries and frameworks to the app manually in CMake. For some reason, find_package(Qt5 ...) doesn't return a complete list of dependencies. Very probable that I'm missing something here, though.

修复2 :确保强制加载libqios以便避免关于丢失的iOS插件的错误消息。在CMake中:

Fix 2: Make sure to force-load libqios in order to avoid the error message about the missing iOS plugin. In CMake:

设置(CMAKE_EXE_LINKER_FLAGS
$ {CMAKE_EXE_LINKER_FLAGS}
-force_load $ {YOUR_QT_ROOT_PATH} / plugins / platforms /libqios.a

修复3 :删除故事板键Info.plist.in。这个步骤我不太详细了解。这些手段的灵感来自于stackoverflow上的这篇帖子。

Fix 3: Remove the storyboard key in the Info.plist.in. This step I don't understand in detail. The means was inspired by this post on stackoverflow.

<密钥GT; UIMainStoryboardFile< /密钥GT;
< string> main< / string>

修复4 :现在顶部的樱桃:对于iOS,您必须使用相应的C格式版本重命名main()函数。显然,Qt带有它自己的入口点,并将你写的那个重命名为 qtmn()。这个qmake魔法由这个脚本执行:你的/ qt / root / path / mkspecs / macx-ios-clang / rename_main.sh。我不详细了解这背后的完整机制。在我的情况下,我没有重命名main的函数签名:

Fix 4: And now the cherry on the top: for iOS you have to rename the main() function with a corresponding "C" formatted version. Apparently, Qt comes with it's own main entry point and renames the one that you wrote as qtmn(). This qmake magic is performed by this script: your/qt/root/path/mkspecs/macx-ios-clang/rename_main.sh. I don't understand the complete mechanics behind this in detail. In my case, I was fine with renaming the function signature of main:

//替换...
int main(int argc,char * argv [])

// ...这一行:
extern Cint qtmn(int argc,char * argv [])

< a href =https://dl.dropboxusercontent.com/u/87662853/analogclock_fixed.zip =nofollow noreferrer>这里又是我在问题中提到的同一个项目,这次是从上面应用的修复。要构建这个项目,只需调用 build_ios.sh ,然后打开在build文件夹中创建的xcodeproj文件。

Here is again the same project I was referring to in the question, this time with the fixes applied from above. To build this project simply call build_ios.sh, and open the xcodeproj file that is created in the build folder.

注意:工作假设是XCode的正确版本(在我的情况下为5.1.1)可用,并且您拥有有效的签名身份(在CMakeLists.txt中更改它!)。此外,在我的示例项目中(见下文),我假设为iOS构建的OpenCV可用。我需要它来解决链接器问题:libpng中缺少一些随OpenCV一起提供的对象。

Note: Working assumptions are that a correct version of XCode (5.1.1 in my case) is available and that you own a valid signing identity (change it in the CMakeLists.txt!). Furthermore, in my sample project (see below) I assume OpenCV built for iOS is available. I needed it to work around a linker problem: there were some objects missing from libpng that are shipped with OpenCV.

我希望这很有帮助。

这篇关于通过CMake构建的ios上Qt应用程序的运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆