Issue
When using qt_add_qml_module
to specify a QML module, how do you handle Qt modules that it depends on (e.g. QtMultimedia)?
If I have class Synthesizer
that extends QML, but which has no dependencies, the following works fine:
qt_add_qml_module(Synth
URI Synth
VERSION 1.0
SOURCES
Synthesizer.h Synthesizer.cpp
)
target_include_directories(Synthplugin
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
)
target_link_libraries(myapp
PRIVATE Qt6::Quick
Synth
)
However if Synthesizer
uses QtMultimedia classes, then this is insufficient, and results in errors like:
Undefined symbols for architecture arm64:
"QAudioSink::start()", referenced from:
Synthesizer::start() in Synthesizer.cpp.o
Solution
I now have a solution that I have been using for a while (but had forgotten this question lay unanswered).
First, make sure the Multimedia
package is loaded. e.g.
find_package(Qt6 6.2 COMPONENTS Qml Quick Multimedia REQUIRED)
Then, after your qt_add_qml_module()
link it to the Synth target:
target_link_libraries(Synth PRIVATE Qt6::Multimedia)
Also note that your target_include_directories()
should be using the target Synth
not Synthplugin
and I would make it PRIVATE as there is no need to make it public. i.e.
target_include_directories(Synth PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
Answered By - Paul Masri-Stone Answer Checked By - Terry (WPSolving Volunteer)