undefined reference errors using QtMultimedia in qt 6.8.3 c++
-
wrote 19 days ago last edited by andi456
Hi,
for some reason the ld does not seem to find the references to the QtMultimedia objects, I'd like to use. In my .h file, I have the following two lines after #include <QtMultimedia/QAudioOutput> and #include <QtMultimedia/QMediaPlayer>:
QAudioOutput *aout; QMediaPlayer *player;
the objects are then instantiated in my .cpp file like this:
player = new QMediaPlayer();
aout = new QAudioOutput();I followed pretty much the instructions in from the audio overview.
My aim is rather simple: Playing a sound after some seconds. An example of the errors occuring:
Error: /home/andi/Projekte/qt/Countdown/qcountdown.cpp:13:(.text+0x557): undefined reference to `QAudioOutput::QAudioOutput(QObject)'*Btw., I'm using a recent version of qtcreator on a gentoo linux box.
Kind regards,
Andreas
-
You do not link against the QtMultmedia library: https://doc.qt.io/qt-6/qaudiooutput.html
-
wrote 19 days ago last edited by
If I try
#include <QAudioOutput>
the compiler tells me: no such file or directory. So how could I make the compiler or linker happy? -
I gave you a link where it's documented what you have to do when using qmake or cmake...
-
If I try
#include <QAudioOutput>
the compiler tells me: no such file or directory. So how could I make the compiler or linker happy?@andi456 hi,
Including a header is not sufficient to "use" a library.
As pointed by @Christian-Ehrlicher, you have to tell the build system that you intend to use said libraries.
-
wrote 16 days ago last edited by
If you have to put forward slashes in a Qt include directive to find the file means you are hosed, or without forward slashes, it can't be found. QAudio is a module that requires you to edit the CMakeLists file and add the reference in two places. I had to do the same thing for Charts and SerialPort.
under the packages, heading i need serialport and charts:
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS SerialPort)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Charts)and here i have to add the libs for linking:
target_link_libraries(myProject PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(myProject PRIVATE
Qt${QT_VERSION_MAJOR}::SerialPort
Qt${QT_VERSION_MAJOR}::PrintSupport
Qt${QT_VERSION_MAJOR}::Charts) -
If you have to put forward slashes in a Qt include directive to find the file means you are hosed, or without forward slashes, it can't be found. QAudio is a module that requires you to edit the CMakeLists file and add the reference in two places. I had to do the same thing for Charts and SerialPort.
under the packages, heading i need serialport and charts:
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS SerialPort)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Charts)and here i have to add the libs for linking:
target_link_libraries(myProject PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(myProject PRIVATE
Qt${QT_VERSION_MAJOR}::SerialPort
Qt${QT_VERSION_MAJOR}::PrintSupport
Qt${QT_VERSION_MAJOR}::Charts)@CJF-the-Elder that's exactly what's written in the docs I linked...
-
wrote 14 days ago last edited by andi456 6 May 2025, 10:42
Thanks for the answers. I figured it out for the cmake build system.
For anyone who stumbles across a similar problem. I had to edit three lines in CMakeLists.txt, i.e., essentially add the keyword "Multimedia" to them:
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Multimedia)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Multimedia)target_link_libraries(Countdown PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Multimedia)
After that compiler and linker do find the corresponding files.
-
7/8