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. How to resolve error LNK2019?
Forum Updated to NodeBB v4.3 + New Features

How to resolve error LNK2019?

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 7.4k Views 2 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.
  • A.MichaelA Offline
    A.MichaelA Offline
    A.Michael
    wrote on last edited by A.Michael
    #1

    Hello everybody,

    my system is follows:

    OS:WIN10
    Qt:5.8.0
    Compiler:MSVC2015
    qtcreator:4.3.0
    

    I created a qtcreator custom control,CEditer(cediterplugin.dll and cediterplugin.lib). It works well.

    .h file as follows:

    CEditer.h:

    #include <QtUiPlugin/QDesignerExportWidget>
    
    namespace Ui {
    class CEditerForm;
    } // namespace Ui
    
    class QDESIGNER_WIDGET_EXPORT CEditer: public QWidget
    {
       Q_OBJECT
    public:
       CEditer();
       XXX
        .
        .
        .
    private:
       Ui::CEditerForm *ui;
    };
    

    Now,I'm going to create another custom control,CEditPanel(ceditpanelplugin.dll and ceditpanelplugin.lib). It contains the CEditer control.

    CEditPanel.h:

    #include <QtUiPlugin/QDesignerExportWidget>
    #include "CEditer.h"
    #pragma comment(lib,"cediterplugin.lib")
    namespace Ui {
        class CEditerPanelForm;
    }
    
    class QDESIGNER_WIDGET_EXPORT CEditerPanel : public QWidget
    {
        Q_OBJECT
    public:
        CEditerPanel();
        XXX
         .
         .
         .
    private:
        Ui::CEditerPanelForm *ui;
    };
    

    "ui_CEditerPanelForm.h"

    #include "CEditer.h"
    
    QT_BEGIN_NAMESPACE
    
    class Ui_CEditerPanelForm
    {
    public:
        QHBoxLayout *horizontalLayout_3;
        CEditer *editer;
        void setupUi(QWidget *CEditerPanelForm)
    {
    ...
    }
    
    namespace Ui {
        class CEditerPanelForm: public Ui_CEditerPanelForm {};
    } // namespace Ui
    

    .pro file segment as follows:

    QT_DESIGNER_PLUGIN_PATH = $$[QT_INSTALL_PLUGINS]/designer
    LIBS += \
            -L$${QT_DESIGNER_PLUGIN_PATH}  \
            -lcediterplugin
    

    When I compiled the program,I got the following link error:

    ceditpanelplugin.obj : error LNK2019: unresolved external symbol "public: static struct QMetaObject const CEditer::staticMetaObject" (?staticMetaObject@CEditer@@2UQMetaObject@@B),referenced in function "public: static class QString __cdecl CEditer::tr(char const *,char const *,int)" (?tr@CEditer@@SA?AVQString@@PBD0H@Z) 
    ceditpanel.obj : error LNK2001: unresolved external symbol  "public: static struct QMetaObject const CEditer::staticMetaObject" (?staticMetaObject@CEditer@@2UQMetaObject@@B)
    moc_ceditpanel.obj : error LNK2001: unresolved external symbol  "public: static struct QMetaObject const CEditer::staticMetaObject" (?staticMetaObject@CEditer@@2UQMetaObject@@B)
    

    I guess maybe the problem is dllexport or dllimport settings,But I don't know how to solve the error.

    someone can help me?

    m.sueM 1 Reply Last reply
    0
    • A.MichaelA A.Michael

      Hello everybody,

      my system is follows:

      OS:WIN10
      Qt:5.8.0
      Compiler:MSVC2015
      qtcreator:4.3.0
      

      I created a qtcreator custom control,CEditer(cediterplugin.dll and cediterplugin.lib). It works well.

      .h file as follows:

      CEditer.h:

      #include <QtUiPlugin/QDesignerExportWidget>
      
      namespace Ui {
      class CEditerForm;
      } // namespace Ui
      
      class QDESIGNER_WIDGET_EXPORT CEditer: public QWidget
      {
         Q_OBJECT
      public:
         CEditer();
         XXX
          .
          .
          .
      private:
         Ui::CEditerForm *ui;
      };
      

      Now,I'm going to create another custom control,CEditPanel(ceditpanelplugin.dll and ceditpanelplugin.lib). It contains the CEditer control.

      CEditPanel.h:

      #include <QtUiPlugin/QDesignerExportWidget>
      #include "CEditer.h"
      #pragma comment(lib,"cediterplugin.lib")
      namespace Ui {
          class CEditerPanelForm;
      }
      
      class QDESIGNER_WIDGET_EXPORT CEditerPanel : public QWidget
      {
          Q_OBJECT
      public:
          CEditerPanel();
          XXX
           .
           .
           .
      private:
          Ui::CEditerPanelForm *ui;
      };
      

      "ui_CEditerPanelForm.h"

      #include "CEditer.h"
      
      QT_BEGIN_NAMESPACE
      
      class Ui_CEditerPanelForm
      {
      public:
          QHBoxLayout *horizontalLayout_3;
          CEditer *editer;
          void setupUi(QWidget *CEditerPanelForm)
      {
      ...
      }
      
      namespace Ui {
          class CEditerPanelForm: public Ui_CEditerPanelForm {};
      } // namespace Ui
      

      .pro file segment as follows:

      QT_DESIGNER_PLUGIN_PATH = $$[QT_INSTALL_PLUGINS]/designer
      LIBS += \
              -L$${QT_DESIGNER_PLUGIN_PATH}  \
              -lcediterplugin
      

      When I compiled the program,I got the following link error:

      ceditpanelplugin.obj : error LNK2019: unresolved external symbol "public: static struct QMetaObject const CEditer::staticMetaObject" (?staticMetaObject@CEditer@@2UQMetaObject@@B),referenced in function "public: static class QString __cdecl CEditer::tr(char const *,char const *,int)" (?tr@CEditer@@SA?AVQString@@PBD0H@Z) 
      ceditpanel.obj : error LNK2001: unresolved external symbol  "public: static struct QMetaObject const CEditer::staticMetaObject" (?staticMetaObject@CEditer@@2UQMetaObject@@B)
      moc_ceditpanel.obj : error LNK2001: unresolved external symbol  "public: static struct QMetaObject const CEditer::staticMetaObject" (?staticMetaObject@CEditer@@2UQMetaObject@@B)
      

      I guess maybe the problem is dllexport or dllimport settings,But I don't know how to solve the error.

      someone can help me?

      m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by
      #2

      @A.Michael

      Hi,

      this error usually occurs if CEditor has no Q_OBJECT macro.

      -Michael.

      A.MichaelA 1 Reply Last reply
      0
      • m.sueM m.sue

        @A.Michael

        Hi,

        this error usually occurs if CEditor has no Q_OBJECT macro.

        -Michael.

        A.MichaelA Offline
        A.MichaelA Offline
        A.Michael
        wrote on last edited by
        #3

        @m.sue thank you

        But there are Q_OBJECT macro in my code.

        mrjjM 1 Reply Last reply
        0
        • A.MichaelA A.Michael

          @m.sue thank you

          But there are Q_OBJECT macro in my code.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @A.Michael
          Hi
          have you check that $$[QT_INSTALL_PLUGINS] actually maps to the place where the .lib and dll are ?

          message({$$[QT_INSTALL_PLUGINS])

          for me it gives
          Project MESSAGE: {C:/Qt/5.8/msvc2015/plugins}

          But the path where my Designer plugin needs to be is
          C:/Qt/Tools/QtCreator/bin/plugins/designer

          Your setup might vary of course but do check what the variable contains.

          A.MichaelA 1 Reply Last reply
          2
          • mrjjM mrjj

            @A.Michael
            Hi
            have you check that $$[QT_INSTALL_PLUGINS] actually maps to the place where the .lib and dll are ?

            message({$$[QT_INSTALL_PLUGINS])

            for me it gives
            Project MESSAGE: {C:/Qt/5.8/msvc2015/plugins}

            But the path where my Designer plugin needs to be is
            C:/Qt/Tools/QtCreator/bin/plugins/designer

            Your setup might vary of course but do check what the variable contains.

            A.MichaelA Offline
            A.MichaelA Offline
            A.Michael
            wrote on last edited by A.Michael
            #5

            @mrjj Thank you for your answer.

            There's nothing wrong with my .pro file. I'm pretty sure.

            Everything is OK when I compiled a EXE file with cediterplugin.dll and cediterplugin.lib.

            The link error 2019 occurs only when I created a custom control that uses another custom control.

            The only difference between a exe program and a custom control plugin is the QDESIGNER_WIDGET_EXPORT .

            QDESIGNER_WIDGET_EXPORT is a null value, when compiling a exe program

            so, I guess it might be the QDESIGNER_WIDGET_EXPORT setting problem.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Did you follow the Splitting up the plugin recommendation in the custom widget for Designer documentation ?

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

              A.MichaelA 1 Reply Last reply
              0
              • SGaistS SGaist

                Hi,

                Did you follow the Splitting up the plugin recommendation in the custom widget for Designer documentation ?

                A.MichaelA Offline
                A.MichaelA Offline
                A.Michael
                wrote on last edited by A.Michael
                #7

                @SGaist thanks for reminding me

                I have two custom widgets, A(a.dll,a.lib) and B(b.dll,b.lib) .

                linking a custom widget(A) into another custom widget(B) has problems.

                Unable to generate a custom widget library file(b.dll and b.lib)

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Are you linking all dependencies correctly ?

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

                  A.MichaelA 2 Replies Last reply
                  0
                  • SGaistS SGaist

                    Are you linking all dependencies correctly ?

                    A.MichaelA Offline
                    A.MichaelA Offline
                    A.Michael
                    wrote on last edited by
                    #9
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Are you linking all dependencies correctly ?

                      A.MichaelA Offline
                      A.MichaelA Offline
                      A.Michael
                      wrote on last edited by A.Michael
                      #10

                      @SGaist I don't know what's wrong with it.

                      The mistake is easy to reproduce.

                      Two custom designer widgets,examples:

                      The First custom designer widget code as follows:
                      [ FirstCustomWidget.pro]
                      CONFIG += plugin release
                      TARGET = $$qtLibraryTarget(firstcustomwidgetplugin)
                      TEMPLATE = lib

                      HEADERS = firstcustomwidgetplugin.h
                      SOURCES = firstcustomwidgetplugin.cpp
                      RESOURCES = icons.qrc
                      LIBS += -L.

                      greaterThan(QT_MAJOR_VERSION, 4) {
                      QT += designer
                      } else {
                      CONFIG += designer
                      }

                      target.path = $$[QT_INSTALL_PLUGINS]/designer
                      INSTALLS += target

                      include(firstcustomwidget.pri)

                      lib_out_path = $${PWD}/../../LnkTester/build/lib
                      include_out_path = $${PWD}/../../LnkTester/build/include

                      $$[QMAKE_SPEC] {
                      CONFIG(release, debug|release) {
                      QMAKE_POST_LINK += copy /y release\.dll "$${target.path}" &
                      QMAKE_POST_LINK += copy /y release\
                      .dll "$${lib_out_path}" &
                      QMAKE_POST_LINK += copy /y release\*.lib "$${lib_out_path}"
                      }
                      }

                      [FirstCustomWidget.h]
                      #ifndef FIRSTCUSTOMWIDGET_H
                      #define FIRSTCUSTOMWIDGET_H

                      #include <QWidget>
                      #include <QLabel>
                      #include <QPixmap>
                      #include <QtUiPlugin/QDesignerExportWidget>

                      class QDESIGNER_WIDGET_EXPORT FirstCustomWidget : public QWidget
                      {
                      Q_OBJECT
                      public:
                      FirstCustomWidget(QWidget * parent = 0);
                      private:
                      QLabel * _label;
                      };
                      #endif

                      [ FirstCustomWidget.cpp]
                      #include "firstcustomwidget.h"

                      FirstCustomWidget::FirstCustomWidget(QWidget * parent) :
                      QWidget(parent), _label(new QLabel(this))
                      {
                      }

                      [firstcustomwidgetplugin.h] [firstcustomwidgetplugin.cpp]
                      These two files are generic

                      The Second custom designer widget code as follows:
                      [SecondCustomWidget.pro]
                      CONFIG += plugin release
                      TARGET = $$qtLibraryTarget(secondcustomwidgetplugin)
                      TEMPLATE = lib

                      HEADERS = secondcustomwidgetplugin.h
                      SOURCES = secondcustomwidgetplugin.cpp
                      RESOURCES = icons.qrc
                      LIBS += -L.

                      greaterThan(QT_MAJOR_VERSION, 4) {
                      QT += designer
                      } else {
                      CONFIG += designer
                      }

                      target.path = $$[QT_INSTALL_PLUGINS]/designer
                      INSTALLS += target

                      include(secondcustomwidget.pri)

                      lib_out_path = $${PWD}/../../LnkTester/build/lib

                      INCLUDEPATH += $${PWD}/../../LnkTester/FirstCustomWidget

                      $$[QMAKE_SPEC] {
                      CONFIG(release, debug|release) {
                      LIBS += -L$${lib_out_path} -lfirstcustomwidgetplugin
                      }
                      }

                      [secondcustomwidget.h]
                      #ifndef SECONDCUSTOMWIDGET_H
                      #define SECONDCUSTOMWIDGET_H

                      #include <QWidget>
                      #include <QtUiPlugin/QDesignerExportWidget>
                      #include "firstcustomwidget.h"

                      class QDESIGNER_WIDGET_EXPORT SecondCustomWidget : public QWidget
                      {
                      Q_OBJECT
                      public:
                      SecondCustomWidget(QWidget * parent = 0);
                      ~SecondCustomWidget();
                      private:
                      FirstCustomWidget *_cwidget;
                      };

                      #endif

                      [secondcustomwidget.cpp]
                      #include "secondcustomwidget.h"

                      SecondCustomWidget::SecondCustomWidget(QWidget *parent) :
                      QWidget(parent),_cwidget(new FirstCustomWidget(this))
                      {
                      }

                      SecondCustomWidget::~SecondCustomWidget()
                      {
                      delete _cwidget;
                      }

                      [secondcustomwidgetplugin.h] [secondcustomwidgetplugin.cpp]
                      These two files are generic

                      the lnk error is as follows:
                      Generating Code...
                      link /NOLOGO /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO /DLL /SUBSYSTEM:WINDOWS /OUT:release\secondcustomwidgetplugin.dll @E:\TEMP\nm4C1A.tmp
                      Creating library release\secondcustomwidgetplugin.lib and object release\secondcustomwidgetplugin.exp
                      secondcustomwidgetplugin.obj : error LNK2019: unresolved external symbol "public: static struct QMetaObject const FirstCustomWidget::staticMetaObject" (?staticMetaObject@FirstCustomWidget@@2UQMetaObject@@B) referenced in function "public: static class QString __cdecl FirstCustomWidget::tr(char const *,char const *,int)" (?tr@FirstCustomWidget@@SA?AVQString@@PBD0H@Z)
                      secondcustomwidget.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const FirstCustomWidget::staticMetaObject" (?staticMetaObject@FirstCustomWidget@@2UQMetaObject@@B)
                      moc_secondcustomwidget.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const FirstCustomWidget::staticMetaObject" (?staticMetaObject@FirstCustomWidget@@2UQMetaObject@@B)
                      release\secondcustomwidgetplugin.dll : fatal error LNK1120: 1 unresolved externals

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        So you are not doing the splitting suggested in the documentation I linked to ?

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

                        A.MichaelA 1 Reply Last reply
                        0
                        • SGaistS SGaist

                          So you are not doing the splitting suggested in the documentation I linked to ?

                          A.MichaelA Offline
                          A.MichaelA Offline
                          A.Michael
                          wrote on last edited by
                          #12

                          @SGaist Thank you very much.

                          I solved the problem.The staticlib option must be used.

                          "CONFIG += staticlib"

                          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