【发布时间】:2016-06-07 08:45:12
【问题描述】:
我是一名 CMake 初学者,在为 MacOS X 创建 Qt 应用程序包时遇到问题。让我们考虑一个仅在一个 main.cpp 文件中的简单小部件“helloworld”应用程序。
// main.cpp
#include <QApplication>
#include <QLabel>
int main(int argc, char** argv)
{
QApplication app(argc,argv);
QLabel lbl("Hello");
lbl.show();
return app.exec();
}
CMakeLists.txt 文件也很简单。
# CMakeLists.txt
cmake_minimum_required( VERSION 3.0 )
project( QtBundle )
set( CMAKE_INCLUDE_CURRENT_DIR ON )
set( CMAKE_AUTOMOC ON )
set( SOURCES main.cpp )
find_package( Qt5Widgets REQUIRED )
add_executable( ${PROJECT_NAME} MACOSX_BUNDLE ${SOURCES} )
qt5_use_modules( ${PROJECT_NAME} Widgets )
我运行cmake .. -DCMAKE_PREFIX_PATH=/path/to/Qt5.5.1/ 并在build 目录中生成Makefile。
然后我运行make 并拥有我想要的QtBundle.app 目录和QtBundle.app/Contents/MacOS/QtBundle 可执行文件,好的。
但是当我启动它时,我得到:
This application failed to start because it could not find or load the Qt platform plugin "cocoa".
Reinstalling the application may fix this problem.
Abort trap: 6
据我了解,发生错误是因为应用程序包没有任何 Qt 东西(框架库和插件),所以我运行 macdeployqt 并使用框架和插件文件夹中的大量文件填充包目录并且应用程序能够运行并重新定位到另一个系统。
它部分解决了问题,但我想用 CMake 和 BundleUtilities 填充捆绑包,并且不使用 macdeployqt 工具。
不幸的是,我没有找到任何使用 BundleUtilities 进行 Qt5 部署的好的简单示例。
有人可以帮助我修改我的“helloworld”示例,使 CMake 自动创建准备部署的包吗?
提前致谢。
主要问题:如何使用 CMake BundleUtilities 获取可重定位应用程序?
【问题讨论】:
-
我也在寻找答案。你有办法解决这个问题吗?我发现的所有东西要么来自上一个时代,要么描述得不好并且没有显示出来。
-
@light2yellow 不,我不使用 BundleUtilities,而是使用 macdeployqt 并在安装步骤中使用 cmake 复制必要的文件,并使用 Packages 制作包。它有效。
-
无论如何我找到了一个很好的例子。看看 avogadro 或其他套件项目。