Undefined reference to `QMediaPlayer::QMediaPlayer(QObject*)' linker error when building under Qt 6.4
-
So do you actually link against the Qt multimedia library?
-
Linking CXX executable /build/bin/sample
I don't see an executable named 'sample' in your CMakeLists.txt you linked to.
-
That was the old executable name, sorry.
Here's the correct error output.
8.450 [36/36] Linking CXX executable /build/bin/sample_media_player 8.450 FAILED: /build/bin/sample_media_player 8.450 : && /usr/bin/g++ CMakeFiles/sample_media_player.dir/sample_media_player_autogen/mocs_compilation.cpp.o CMakeFiles/sample_media_player.dir/main.cpp.o CMakeFiles/sample_media_player.dir/sample_media_player_qmltyperegistrations.cpp.o CMakeFiles/sample_media_player.dir/.rcc/qrc_qmake_Components.cpp.o CMakeFiles/sample_media_player.dir/.rcc/qmlcache/sample_media_player_qmlcache_loader.cpp.o CMakeFiles/sample_media_player.dir/.rcc/qmlcache/sample_media_player_Main_qml.cpp.o CMakeFiles/sample_media_player.dir/.rcc/qrc_sample_media_player_raw_qml_0.cpp.o -o /build/bin/sample_media_player CMakeFiles/sample_player_plugin_init.dir/./sample_player_plugin_init.cpp.o CMakeFiles/sample_player_resources_1.dir/./.rcc/qrc_qmake_SamplePlayer.cpp.o SamplePlayer/libsample_player_plugin.a /usr/lib/x86_64-linux-gnu/libQt6Multimedia.so.6.4.2 /usr/lib/x86_64-linux-gnu/libQt6Gui.so.6.4.2 /usr/lib/x86_64-linux-gnu/libGLX.so /usr/lib/x86_64-linux-gnu/libOpenGL.so libsample_player.a /usr/lib/x86_64-linux-gnu/libQt6Qml.so.6.4.2 /usr/lib/x86_64-linux-gnu/libQt6Network.so.6.4.2 /usr/lib/x86_64-linux-gnu/libQt6Core.so.6.4.2 && : 8.450 /usr/bin/ld: libsample_player.a(sample_player.cpp.o): in function `SamplePlayer::SamplePlayer(QObject*)': 8.450 sample_player.cpp:(.text+0xdb): undefined reference to `QMediaPlayer::QMediaPlayer(QObject*)' 8.450 /usr/bin/ld: libsample_player.a(sample_player.cpp.o): in function `SamplePlayer::~SamplePlayer()': 8.450 sample_player.cpp:(.text+0x11a): undefined reference to `QMediaPlayer::~QMediaPlayer()' 8.450 /usr/bin/ld: libsample_player.a(mocs_compilation.cpp.o): in function `SamplePlayer::qt_metacast(char const*)': 8.450 mocs_compilation.cpp:(.text+0x167): undefined reference to `QMediaPlayer::qt_metacast(char const*)' 8.450 /usr/bin/ld: libsample_player.a(mocs_compilation.cpp.o): in function `SamplePlayer::qt_metacall(QMetaObject::Call, int, void**)': 8.450 mocs_compilation.cpp:(.text+0x196): undefined reference to `QMediaPlayer::qt_metacall(QMetaObject::Call, int, void**)' 8.450 /usr/bin/ld: libsample_player.a(mocs_compilation.cpp.o):(.data.rel.ro+0x0): undefined reference to `QMediaPlayer::staticMetaObject' 8.450 /usr/bin/ld: libsample_player.a(mocs_compilation.cpp.o):(.data.rel.ro._ZTI12SamplePlayer[_ZTI12SamplePlayer]+0x10): undefined reference to `typeinfo for QMediaPlayer' 8.450 collect2: error: ld returned 1 exit status 8.450 ninja: build stopped: subcommand failed.
-
sample_player.cpp is not built by sample_media_player executable but sample_player lib so this library should correctly link against Qt6::Multimedia. Otherwise the link order is wrong (and the whole dependency handling - when some lib is using this library then it should also link against it).
-
<sample_player> library should correctly link against Qt6::Multimedia
How that can be done in my CMakeLists.txt file?
-
<sample_player> library should correctly link against Qt6::Multimedia
How that can be done in my CMakeLists.txt file?
@shamaoke said in Undefined reference to `QMediaPlayer::QMediaPlayer(QObject*)' linker error when building under Qt 6.4:
How that can be done in my CMakeLists.txt file?
The same way you did it with your executable by using target_link_libraries()... Why should this be different between an executable and a library?
-
-
You should link Qt6::Multimedia PUBLIC as the public header of your library is using this library (header) in a public header. Same goes for Qt6:Qml