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')
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Unsolved 3rd Party Software
13 Posts 5 Posters 855 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.
  • X Offline
    X Offline
    xanthas
    wrote on 25 Nov 2024, 06:29 last edited by
    #1

    For the past 4 days I am stuck here with this error, can't find help on google search:

    C:\Users\D Besta\Documents\sample_qgis_pro\mainwindow.cpp:13: error: undefined reference to `__imp__ZN18QgsUserInputWidgetC1EP7QWidget'
    

    Here are my files:

    .pro file
    QT       += core gui xml
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    CONFIG += c++17
    
    # You can make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += \
        main.cpp \
        mainwindow.cpp
    
    HEADERS += \
        mainwindow.h
    
    FORMS += \
        mainwindow.ui
    
    INCLUDEPATH += C:/OSGeo4W/apps/qgis-qt6-dev/include C:/OSGeo4W/include #C:\OSGeo4W\QGIS\src\app C:\OSGeo4W\apps\Qt6\include #C:\OSGeo4W\QGIS\src\core C:\OSGeo4W\apps\qgis-dev\include
    
    #LIBS += "C:\OSGeo4W\apps\qgis-rel-dev\lib" -lqgis_core -lqgis_gui #C:\OSGeo4W\apps\qgis-qt6-dev\lib\qgis_gui.lib C:\OSGeo4W\apps\qgis-qt6-dev\lib\qgis_core.lib
    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
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    .h File
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <qgsuserinputwidget.h>
    #include <QWidget>
    
    QT_BEGIN_NAMESPACE
    namespace Ui {
    class MainWindow;
    }
    QT_END_NAMESPACE
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
    
    private:
        Ui::MainWindow *ui;
        QWidget *tested=nullptr;
        QgsUserInputWidget *testwidget=nullptr;
    };
    #endif // MAINWINDOW_H
    
    mainwindow.cpp File
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        setGeometry(0, 0, 200, 200);
        setMinimumSize(200, 200);
        setWindowTitle("Integrated_Ground_Control_Station");
    
        testwidget = new QgsUserInputWidget(this);
        testwidget->setStyleSheet("background-color: rgb(0,0,0)");
        testwidget->show();
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
        delete testwidget;
    }
    
    1 Reply Last reply
    0
    • C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 25 Nov 2024, 06:58 last edited by
      #2

      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.

      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 25 Nov 2024, 07:08
      4
      • C Christian Ehrlicher
        25 Nov 2024, 06:58

        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 25 Nov 2024, 07:08 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
        • C Online
          C Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 25 Nov 2024, 07:20 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 25 Nov 2024, 07:34
          2
          • C Christian Ehrlicher
            25 Nov 2024, 07:20

            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 25 Nov 2024, 07:34 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 &#x60;__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 25 Nov 2024, 08:30
            0
            • X xanthas
              25 Nov 2024, 07:34

              @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 &#x60;__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 25 Nov 2024, 08:30 last edited by
              #6

              @xanthas said in QGiS Qmake Compile Error (error: undefined reference to &#x60;__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 25 Nov 2024, 10:04
              0
              • jsulmJ jsulm
                25 Nov 2024, 08:30

                @xanthas said in QGiS Qmake Compile Error (error: undefined reference to &#x60;__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 25 Nov 2024, 10:04 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
                  25 Nov 2024, 08:30

                  @xanthas said in QGiS Qmake Compile Error (error: undefined reference to &#x60;__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 25 Nov 2024, 10:57 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 25 Nov 2024, 13:28
                  0
                  • X xanthas
                    25 Nov 2024, 10:57

                    @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 25 Nov 2024, 13:28 last edited by
                    #9

                    @xanthas said in QGiS Qmake Compile Error (error: undefined reference to &#x60;__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 26 Nov 2024, 05:38
                    1
                    • jsulmJ jsulm
                      25 Nov 2024, 13:28

                      @xanthas said in QGiS Qmake Compile Error (error: undefined reference to &#x60;__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 26 Nov 2024, 05:38 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 26 Nov 2024, 08:15
                      0
                      • X xanthas
                        26 Nov 2024, 05:38

                        @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 26 Nov 2024, 08:15 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 5 Dec 2024, 07:17
                        0
                        • X xanthas referenced this topic on 3 Dec 2024, 11:33
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 3 Dec 2024, 21:29 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
                            26 Nov 2024, 08:15

                            @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 5 Dec 2024, 07:17 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

                            1/13

                            25 Nov 2024, 06:29

                            • Login

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