Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Undefined reference to `QMediaPlayer::QMediaPlayer(QObject*)' linker error when building under Qt 6.4
Forum Updated to NodeBB v4.3 + New Features

Undefined reference to `QMediaPlayer::QMediaPlayer(QObject*)' linker error when building under Qt 6.4

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 2 Posters 622 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Christian EhrlicherC Online
    Christian EhrlicherC Online
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #2

    So do you actually link against the Qt multimedia library?

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    1 Reply Last reply
    0
    • S Offline
      S Offline
      shamaoke
      wrote on last edited by
      #3

      I think I do. Here's the line in the build control file.

      1 Reply Last reply
      0
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #4

        Linking CXX executable /build/bin/sample

        I don't see an executable named 'sample' in your CMakeLists.txt you linked to.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        0
        • S Offline
          S Offline
          shamaoke
          wrote on last edited by
          #5

          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.
          
          1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #6

            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).

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            1
            • S Offline
              S Offline
              shamaoke
              wrote on last edited by
              #7

              <sample_player> library should correctly link against Qt6::Multimedia

              How that can be done in my CMakeLists.txt file?

              Christian EhrlicherC 1 Reply Last reply
              0
              • S shamaoke

                <sample_player> library should correctly link against Qt6::Multimedia

                How that can be done in my CMakeLists.txt file?

                Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @shamaoke said in Undefined reference to &#x60;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?

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                1
                • S Offline
                  S Offline
                  shamaoke
                  wrote on last edited by
                  #9

                  I made changes to the CMakeLists.txt file. Now it successfully build under Qt 6.4.

                  I appreciate your help.

                  1 Reply Last reply
                  0
                  • S shamaoke has marked this topic as solved on
                  • Christian EhrlicherC Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    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

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      shamaoke
                      wrote on last edited by
                      #11

                      Done! Thank you very much!

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved