Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. CMake Undefined Reference to `QGraphicsItem:: ...
Qt 6.12 LTS is out! See what's new in the release blog

CMake Undefined Reference to `QGraphicsItem:: ...

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 3.1k Views 1 Watching
  • 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.
  • K Offline
    K Offline
    Karlos
    wrote on last edited by
    #1

    Hello,

    I am fairly new to CMake and C++ development and I am trying to convert a Qt Creator project to CMake so that I can use CLion for development, however I am getting an error when trying to build the project.

    From what I understand the project uses Qt5::Core, Qt5::Gui and Qt5::Widgets and contains no .qrc files.

    The errors returned are of the form:

    CMakeFiles\zeus.dir/objects.a(TileView.cpp.obj):TileView.cpp:(.rdata$_ZTV8TileView[__ZTV8TileView]+0x8c): undefined reference to `QGraphicsItem::itemChange(QGraphicsItem::GraphicsItemChange, QVariant const&)'
    CMakeFiles\zeus.dir/objects.a(TileView.cpp.obj):TileView.cpp:(.rdata$_ZTV8TileView[__ZTV8TileView]+0x90): undefined reference to `QGraphicsItem::supportsExtension(QGraphicsItem::Extension) const'
    CMakeFiles\zeus.dir/objects.a(TileView.cpp.obj):TileView.cpp:(.rdata$_ZTV8TileView[__ZTV8TileView]+0x94): undefined reference to `QGraphicsItem::setExtension(QGraphicsItem::Extension, QVariant const&)'
    CMakeFiles\zeus.dir/objects.a(TileView.cpp.obj):TileView.cpp:(.rdata$_ZTV8TileView[__ZTV8TileView]+0x98): undefined reference to `QGraphicsItem::extension(QVariant const&) const'
    CMakeFiles\zeus.dir/objects.a(TileView.cpp.obj): In function `ZN8TileViewD1Ev':
    .../src/viewer/TileView.hpp:18: undefined reference to `_imp___ZN13QGraphicsItemD2Ev'
    CMakeFiles\zeus.dir/objects.a(main.cpp.obj): In function `main':
    .../main.cpp:7: undefined reference to `_imp___ZN12QApplicationC1ERiPPci'
    .../src/main.cpp:11: undefined reference to `_imp___ZN7QWidget13showMaximizedEv'
    .../src/main.cpp:13: undefined reference to `_imp___ZN12QApplication4execEv'
    .../src/main.cpp:7: undefined reference to `_imp___ZN12QApplicationD1Ev'
    .../src/main.cpp:7: undefined reference to `_imp___ZN12QApplicationD1Ev'
    

    and there is many more printed out!

    The original .pro file is located here.
    My attempt at a CMake file is located here.

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

      What compiler do you use and what Qt version (and for which compiler) did you download Qt?

      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
      • K Offline
        K Offline
        Karlos
        wrote on last edited by
        #3

        I am using the Windows MinGW64 i686-8.1.0-posix-dwarf-rt_v6-rev0 compiler and have installed Qt 5.15.2.

        I also have these variables passed in to Cmake

        -DQt5_DIR=C:\Qt\5.15.2\mingw81_64\lib\cmake\Qt5 -DCMAKE_PREFIX_PATH=C:\Qt\5.15.2\mingw81_64\lib\cmake
        

        and linking the required yaml-cpp library with the build option -lyaml-cpp.

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

          @Karlos said in CMake Undefined Reference to `QGraphicsItem:: ...:

          TileView.cpp.obj

          This is for sure not MinGW. You can not mix MingW and MSVC libraries. Make sure you use the compiler for which you've installed Qt (msvc or mingw, you still not answered this).

          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
          • K Offline
            K Offline
            Karlos
            wrote on last edited by
            #5

            When installing Qt I selected "Qt 5.15.2 for MinGW 8.1.0 64-bit for desktop application development" and then installed MinGW 8.1.0 from the mingw-w64 site.

            My toolchain in CLion is set up to use MinGW as the compiler. Do I need to install and use MSVC?

            jsulmJ 1 Reply Last reply
            0
            • K Karlos

              When installing Qt I selected "Qt 5.15.2 for MinGW 8.1.0 64-bit for desktop application development" and then installed MinGW 8.1.0 from the mingw-w64 site.

              My toolchain in CLion is set up to use MinGW as the compiler. Do I need to install and use MSVC?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Karlos said in CMake Undefined Reference to `QGraphicsItem:: ...:

              and then installed MinGW 8.1.0 from the mingw-w64 site

              You should prefer MinGW provided by Qt installer instead.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              3
              • K Offline
                K Offline
                Karlos
                wrote on last edited by Karlos
                #7

                Thank you both for your swift replies. I'll update my toolchain so that it uses the MinGW compiler provided with the Qt installation. I am unavailable to reply for a few hours but will update this thread when I can.

                EDIT: This worked! Many thanks!

                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
                • Unsolved