Я безуспешно пытался распространять базовое консольное приложение Qt с помощью CMake.
Давайте рассмотрим эти 2 файла:
main.cpp
#include <QDebug>
int main(int argc, char *argv[])
{
qDebug() << "Hello Wolrd!";
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.12)
project(HelloWorld)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5Widgets REQUIRED)
add_executable(${PROJECT_NAME} main.cpp)
qt5_use_modules(${PROJECT_NAME} Widgets)
Далее я компилирую файл main.cpp
, выполнив:
$ cmake .
-- The C compiler identification is AppleClang 10.0.1.10010046
-- The CXX compiler identification is AppleClang 10.0.1.10010046
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /path/to/HelloWorld
$ make
Scanning dependencies of target HelloWorld_autogen
[ 25%] Automatic MOC for target HelloWorld
[ 25%] Built target HelloWorld_autogen
Scanning dependencies of target HelloWorld
[ 50%] Building CXX object CMakeFiles/HelloWorld.dir/HelloWorld_autogen/mocs_compilation.cpp.o
[ 75%] Building CXX object CMakeFiles/HelloWorld.dir/main.cpp.o
[100%] Linking CXX executable HelloWorld
[100%] Built target HelloWorld
И я получаю двоичный файл HelloWorld
.
Проблема возникает, когда я пытаюсь запустить последний файл на другом компьютере, на котором не установлен Qt.Я получаю следующую ошибку:
dyld: Library not loaded: @rpath/QtWidgets.framework/Versions/5/QtWidgets
Referenced from: /path/to/HelloWorld/./HelloWorld
Reason: image not found
./test.sh: line 4: 68737 Abort trap: 6 ./HelloWorld
Чего не хватает, чтобы это работало как отдельное приложение?
Среда:
- MacOs Mojave (10.14.4)
- Qt 5.10.1