Using Cmake to compile QtQuick and QM: How to load qt plugins
Hello,
I am trying to compile the wireframe example using Cmake. I am able to to get a good build using the CMakeLists.txt below. However, when I run the executable I get the an error associate with the loading of plugins. It appears that the executable is looking for the plugins in an other application (gleamviz)?? Is there a way to point Qt in the right direction for the plugins in the CMakeLists.txt?
Error message:
[reuben@reuben-mba build]$ ./gui/eema_gui
qrc:/main.qml:51:1: plugin cannot be loaded for module "QtQuick": Cannot load library /Applications/GLEAMviz-5/gleamviz.app/Contents/Frameworks/qml/QtQuick.2/libqtquick2plugin.dylib: (dlopen(/Applications/GLEAMviz-5/gleamviz.app/Contents/Frameworks/qml/QtQuick.2/libqtquick2plugin.dylib, 133): Library not loaded: @executable_path/../Frameworks/QtQuick.framework/Versions/5/QtQuick
Referenced from: /Applications/GLEAMviz-5/gleamviz.app/Contents/Frameworks/qml/QtQuick.2/libqtquick2plugin.dylib
Reason: image not found)
[reuben@reuben-mba build]$
CMakeLists.txt:
# configure Qt
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
find_package(Qt5 COMPONENTS Core Quick QML 3DQuickExtras QuickControls2 REQUIRED)
foreach(plugin ${Qt5Core_PLUGINS})
get_target_property(_loc ${plugin} LOCATION)
message("Plugin ${plugin} is at location ${_loc}")
endforeach()
# add the qml.qrc file
qt5_add_resources(qml_QRC wireframe.qrc)
file(GLOB_RECURSE CODE_FILES *.cpp)
add_executable(eema_gui
${CODE_FILES}
${qml_QRC}
)
target_link_libraries(eema_gui Qt5::Core Qt5::Qml Qt5::Quick Qt5::3DQuickExtras Qt5::QuickControls2)
Re: Using Cmake to compile QtQuick and QM: How to load qt plugins
Running the executable you build with CMake has nothing to do with CMake or the CMakeLists.txt file. It's your runtime environment that's to blame. All of the plugins and/or dynamic (shared) libraries used by your program have to be "findable" when the program runs. This means they either have to be in a location the executable looks by default (eg. the executable's directory) or in a directory that can be found in the system PATH.
The error message tells you what the runtime is looking for and that's where the problem lies, but I am not familiar enough with Mac OS to tell you exactly how to fix this.