Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. QGiS Qmake Compile Error (error: undefined reference to `__imp__ZN18QgsUserInputWidgetC1EP7QWidget')
Forum Updated to NodeBB v4.3 + New Features

QGiS Qmake Compile Error (error: undefined reference to `__imp__ZN18QgsUserInputWidgetC1EP7QWidget')

Scheduled Pinned Locked Moved Unsolved 3rd Party Software
13 Posts 5 Posters 2.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.
  • Christian EhrlicherC Christian Ehrlicher

    According to the documentation, this class is in the gui subdir, so it's in the gui module as you can see here: https://github.com/qgis/QGIS/blob/master/src/gui/CMakeLists.txt#L1674

    You don't link against this library so the linker can not find it.

    X Offline
    X Offline
    xanthas
    wrote on last edited by
    #3

    @Christian-Ehrlicher Ok Thank you
    Can you please share any example of writing a simple QGiS project in Qt C++ or the link to something that can help me learn using QGiS
    Everything available online is for PyQGiS only.

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

      Since I don't use neither QGis nor qmake - not really.
      As you can see you link against a lot of qgis libraries, but not against the gui module - add it.

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

      X 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        Since I don't use neither QGis nor qmake - not really.
        As you can see you link against a lot of qgis libraries, but not against the gui module - add it.

        X Offline
        X Offline
        xanthas
        wrote on last edited by
        #5

        @Christian-Ehrlicher If I have understood correctly, you meant that I should link library related gui module of QGiS. Can you please let me know how to do it
        Or else I haven't understoor properly what you meant. Can you please elaborate the suggestion or solution you provided

        @Christian-Ehrlicher said in QGiS Qmake Compile Error (error: undefined reference to `__imp__ZN18QgsUserInputWidgetC1EP7QWidget'):

        As you can see you link against a lot of qgis libraries, but not against the gui module - add it.

        jsulmJ 1 Reply Last reply
        0
        • X xanthas

          @Christian-Ehrlicher If I have understood correctly, you meant that I should link library related gui module of QGiS. Can you please let me know how to do it
          Or else I haven't understoor properly what you meant. Can you please elaborate the suggestion or solution you provided

          @Christian-Ehrlicher said in QGiS Qmake Compile Error (error: undefined reference to `__imp__ZN18QgsUserInputWidgetC1EP7QWidget'):

          As you can see you link against a lot of qgis libraries, but not against the gui module - add it.

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

          @xanthas said in QGiS Qmake Compile Error (error: undefined reference to `__imp__ZN18QgsUserInputWidgetC1EP7QWidget'):

          Can you please let me know how to do it

          Come on - you already link many libraries - what is the problem to add one more?

          LIBS += C:/OSGeo4W/apps/qgis-qt6-dev/lib/qgis_3d.lib \
                  C:/OSGeo4W/apps/qgis-qt6-dev/lib/qgis_analysis.lib \
                  C:/OSGeo4W/apps/qgis-qt6-dev/lib/qgis_app.lib \
                  C:/OSGeo4W/apps/qgis-qt6-dev/lib/qgis_native.lib \
                  C:/OSGeo4W/apps/qgis-qt6-dev/lib/qgis_server.lib \
                  ADD_HERE_THEGUI_ONE
          

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

          X 2 Replies Last reply
          0
          • jsulmJ jsulm

            @xanthas said in QGiS Qmake Compile Error (error: undefined reference to `__imp__ZN18QgsUserInputWidgetC1EP7QWidget'):

            Can you please let me know how to do it

            Come on - you already link many libraries - what is the problem to add one more?

            LIBS += C:/OSGeo4W/apps/qgis-qt6-dev/lib/qgis_3d.lib \
                    C:/OSGeo4W/apps/qgis-qt6-dev/lib/qgis_analysis.lib \
                    C:/OSGeo4W/apps/qgis-qt6-dev/lib/qgis_app.lib \
                    C:/OSGeo4W/apps/qgis-qt6-dev/lib/qgis_native.lib \
                    C:/OSGeo4W/apps/qgis-qt6-dev/lib/qgis_server.lib \
                    ADD_HERE_THEGUI_ONE
            
            X Offline
            X Offline
            xanthas
            wrote on last edited by xanthas
            #7

            @jsulm Sorry to be a little annoying here
            For me its a bit difficult to understand programming in qt so that's why I asked.
            Thank you for the solution
            I will try and update here

            By the way is there any way I can have the drag and drop option in design area for qgis in the creator itself?

            1 Reply Last reply
            0
            • jsulmJ jsulm

              @xanthas said in QGiS Qmake Compile Error (error: undefined reference to `__imp__ZN18QgsUserInputWidgetC1EP7QWidget'):

              Can you please let me know how to do it

              Come on - you already link many libraries - what is the problem to add one more?

              LIBS += C:/OSGeo4W/apps/qgis-qt6-dev/lib/qgis_3d.lib \
                      C:/OSGeo4W/apps/qgis-qt6-dev/lib/qgis_analysis.lib \
                      C:/OSGeo4W/apps/qgis-qt6-dev/lib/qgis_app.lib \
                      C:/OSGeo4W/apps/qgis-qt6-dev/lib/qgis_native.lib \
                      C:/OSGeo4W/apps/qgis-qt6-dev/lib/qgis_server.lib \
                      ADD_HERE_THEGUI_ONE
              
              X Offline
              X Offline
              xanthas
              wrote on last edited by
              #8

              @jsulm

              .pro File now includes
                  C:/OSGeo4W/apps/qgis-qt6-dev/lib/qgis_gui.lib \
                  C:/OSGeo4W/apps/qgis-qt6-dev/lib/qgis_core.lib
              

              Still the same error
              There can be issue because of the admin permission? But I have installed for ALL Users

              jsulmJ 1 Reply Last reply
              0
              • X xanthas

                @jsulm

                .pro File now includes
                    C:/OSGeo4W/apps/qgis-qt6-dev/lib/qgis_gui.lib \
                    C:/OSGeo4W/apps/qgis-qt6-dev/lib/qgis_core.lib
                

                Still the same error
                There can be issue because of the admin permission? But I have installed for ALL Users

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

                @xanthas said in QGiS Qmake Compile Error (error: undefined reference to `__imp__ZN18QgsUserInputWidgetC1EP7QWidget'):

                There can be issue because of the admin permission?

                No

                Did you do a complete rebuild after changing pro file?

                1. Delete build folder
                2. Run qmake
                3. Build

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

                X 1 Reply Last reply
                1
                • jsulmJ jsulm

                  @xanthas said in QGiS Qmake Compile Error (error: undefined reference to `__imp__ZN18QgsUserInputWidgetC1EP7QWidget'):

                  There can be issue because of the admin permission?

                  No

                  Did you do a complete rebuild after changing pro file?

                  1. Delete build folder
                  2. Run qmake
                  3. Build
                  X Offline
                  X Offline
                  xanthas
                  wrote on last edited by
                  #10

                  @jsulm I tried it just before typing this reply. Also, since last night I have been trying to contact a few friends of mine who have been working with Qt for a while. The conclusion I have got to is that, this problem lies in QGiS and not with Qt. Also, I can't find answers as there are no tutorials related to QGiS Qt C++ programming. I have asked the same query in their forum as well.

                  JonBJ 1 Reply Last reply
                  0
                  • X xanthas

                    @jsulm I tried it just before typing this reply. Also, since last night I have been trying to contact a few friends of mine who have been working with Qt for a while. The conclusion I have got to is that, this problem lies in QGiS and not with Qt. Also, I can't find answers as there are no tutorials related to QGiS Qt C++ programming. I have asked the same query in their forum as well.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #11

                    @xanthas
                    I don't use QGIS or Windows. But a little searching and reading implies to me:

                    • In your stackexchange post I think you do, or might, need to add the qgis_core and qgis_gui libraries. Unless the other libraries use an MSVC feature which auto-adds them.

                    • Make sure that both QGIS and your code are built using the same compiler. I don't know whether you are compiling QGIS yourself or which compiler you are using. It is clearly intended for MSVC, so make sure you are not using MinGW. Make sure you use the same version of MSVC for both.

                    • I have a feeling/hope that you may need to add a couple of DEFINES which you are not doing. In your .pro I believe you should have one of

                    DEFINES += CORE_EXPORT=
                    DEFINES += GUI_EXPORT=
                    

                    or

                    DEFINES += CORE_EXPORT=__declspec(dllimport)
                    DEFINES += GUI_EXPORT=__declspec(dllimport)
                    

                    (possibly the latter). This is an MSVC-ism. Try both (rebuild your code from scratch each time), does it work after e.g. the second pair of definitions?

                    References:
                    https://gis.stackexchange.com/questions/244373/qt-c-application-using-qgis-api/246218#246218
                    https://stackoverflow.com/questions/42201632/qgis-with-standalone-c-application-in-qt-creator
                    https://3nids.wordpress.com/

                    X 1 Reply Last reply
                    0
                    • X xanthas referenced this topic on
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      Hi,

                      Why not use the standard notation:

                      LIBS += -LC:/OSGeo4W/apps/qgis-qt6-dev/lib \
                          -lqgis_gui \
                          -lqgis_core
                      

                      ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • JonBJ JonB

                        @xanthas
                        I don't use QGIS or Windows. But a little searching and reading implies to me:

                        • In your stackexchange post I think you do, or might, need to add the qgis_core and qgis_gui libraries. Unless the other libraries use an MSVC feature which auto-adds them.

                        • Make sure that both QGIS and your code are built using the same compiler. I don't know whether you are compiling QGIS yourself or which compiler you are using. It is clearly intended for MSVC, so make sure you are not using MinGW. Make sure you use the same version of MSVC for both.

                        • I have a feeling/hope that you may need to add a couple of DEFINES which you are not doing. In your .pro I believe you should have one of

                        DEFINES += CORE_EXPORT=
                        DEFINES += GUI_EXPORT=
                        

                        or

                        DEFINES += CORE_EXPORT=__declspec(dllimport)
                        DEFINES += GUI_EXPORT=__declspec(dllimport)
                        

                        (possibly the latter). This is an MSVC-ism. Try both (rebuild your code from scratch each time), does it work after e.g. the second pair of definitions?

                        References:
                        https://gis.stackexchange.com/questions/244373/qt-c-application-using-qgis-api/246218#246218
                        https://stackoverflow.com/questions/42201632/qgis-with-standalone-c-application-in-qt-creator
                        https://3nids.wordpress.com/

                        X Offline
                        X Offline
                        xanthas
                        wrote on last edited by
                        #13

                        @JonB Hi these I have already included.
                        Also, I have seen a few examples at Github. I have tried to compile with MSVC as well as MinGW.
                        These are the errors:

                        moc_india_map_test.obj:-1: error: LNK2001: unresolved external symbol "public: static struct QMetaObject const QgsVectorLayer::staticMetaObject" (?staticMetaObject@QgsVectorLayer@@2UQMetaObject@@B)
                        moc_india_map_test.obj:-1: error: LNK2001: unresolved external symbol "public: static struct QMetaObject const QgsRasterLayer::staticMetaObject" (?staticMetaObject@QgsRasterLayer@@2UQMetaObject@@B)
                        

                        after I try to run the project.

                        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