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.5k 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.
  • 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