Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. VS2012 Linking issue
QtWS25 Last Chance

VS2012 Linking issue

Scheduled Pinned Locked Moved Installation and Deployment
vs2012
7 Posts 2 Posters 2.2k 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.
  • MassiM Offline
    MassiM Offline
    Massi
    wrote on last edited by A Former User
    #1

    Good day,
    I created a vs2012 c++ dll project (no Qt at all) on win7 x64 and I want to use Qt 5.4.1 library in the project. I've downloaded Qt and built it under visual studio 2012 and setup my environment variables following this link
    And I used the following line in the VS2012 command prompt to compile the library with no examples.
    configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop -nomake examples -nomake tests

    On my dll project, I linked the libraries (static and dynamic) Qt\5.4.1\qtbase\lib and included the headers Qt\5.4.1\qtbase\include

    but when I try to use Qt classes like QFile in my code, I got the following error:

    error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QByteArray::~QByteArray(void)" (__imp_??1QByteArray@@QAE@XZ) referenced in function
    

    Any hint?
    Thanks in advance!

    Massi

    Software Design Engineer at Ford - Canada

    jsulmJ 1 Reply Last reply
    0
    • MassiM Massi

      Good day,
      I created a vs2012 c++ dll project (no Qt at all) on win7 x64 and I want to use Qt 5.4.1 library in the project. I've downloaded Qt and built it under visual studio 2012 and setup my environment variables following this link
      And I used the following line in the VS2012 command prompt to compile the library with no examples.
      configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop -nomake examples -nomake tests

      On my dll project, I linked the libraries (static and dynamic) Qt\5.4.1\qtbase\lib and included the headers Qt\5.4.1\qtbase\include

      but when I try to use Qt classes like QFile in my code, I got the following error:

      error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QByteArray::~QByteArray(void)" (__imp_??1QByteArray@@QAE@XZ) referenced in function
      

      Any hint?
      Thanks in advance!

      Massi

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

      @Massi Why do you build Qt by yourself?
      It is much easier to use the Qt Online Installer.
      Do you have to use Qt 5.4.1? It is not the latest version.
      Do you link your app against libQtCore library?

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

      MassiM 1 Reply Last reply
      1
      • jsulmJ jsulm

        @Massi Why do you build Qt by yourself?
        It is much easier to use the Qt Online Installer.
        Do you have to use Qt 5.4.1? It is not the latest version.
        Do you link your app against libQtCore library?

        MassiM Offline
        MassiM Offline
        Massi
        wrote on last edited by
        #3

        @jsulm Many thanks for your reply, This will solve the problem if I add the following libraries in the Additional Dependencies (right click the solution->properties->Linker->Input->Addiotional Dependencies)

        Qt5Cored.lib
        Qt5Guid.lib
        Qt5Widgetsd.lib
        

        (I'm building in debug mode)
        But when I try to inherit my own class from QWidget with the Q_OBJECT macro in it and build the solution, I got the following error:
        error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall SynopticsWidget::metaObject(void)const "

        Same kind of issue. Which library Q_OBJECT come from? I don't have MetaObject.lib

        Again Thanks!

        Massi

        Software Design Engineer at Ford - Canada

        jsulmJ 1 Reply Last reply
        0
        • MassiM Massi

          @jsulm Many thanks for your reply, This will solve the problem if I add the following libraries in the Additional Dependencies (right click the solution->properties->Linker->Input->Addiotional Dependencies)

          Qt5Cored.lib
          Qt5Guid.lib
          Qt5Widgetsd.lib
          

          (I'm building in debug mode)
          But when I try to inherit my own class from QWidget with the Q_OBJECT macro in it and build the solution, I got the following error:
          error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall SynopticsWidget::metaObject(void)const "

          Same kind of issue. Which library Q_OBJECT come from? I don't have MetaObject.lib

          Again Thanks!

          Massi

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

          @Massi Qt has a tool named moc (meta object compiler). This tool generates code for all classes derived from QObject. This generated code needs to be compiled as well. Please read http://doc.qt.io/qt-5.8/moc.html. When using QtCreator/qmake you usually do not have to care about it as it is done for you. Not sure how to do it with Visual Studio. There is a Qt plug-in for Visual Studio which should make your life easier - do you use it?

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

          1 Reply Last reply
          0
          • MassiM Offline
            MassiM Offline
            Massi
            wrote on last edited by
            #5

            @jsulm I have installed the plugging in vs2012 and it resulted by adding a Qt5 tab my vs2012 menu bar but I'm not using it.
            My project was not created as a Qt project. It was already created as a simple dll long time ago and I just want to use Qt library for some graphic displays. Does my dll need to be a QtProject?

            1>SynopticsWidget.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall SynopticsWidget::metaObject(void)const " (?metaObject@SynopticsWidget@@UBEPBUQMetaObject@@XZ)
            1>SynopticsWidget.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall SynopticsWidget::qt_metacast(char const *)" (?qt_metacast@SynopticsWidget@@UAEPAXPBD@Z)
            1>SynopticsWidget.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall SynopticsWidget::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@SynopticsWidget@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
            
            

            I'm stuck on that.
            Best,

            Massi

            Software Design Engineer at Ford - Canada

            jsulmJ 1 Reply Last reply
            0
            • MassiM Massi

              @jsulm I have installed the plugging in vs2012 and it resulted by adding a Qt5 tab my vs2012 menu bar but I'm not using it.
              My project was not created as a Qt project. It was already created as a simple dll long time ago and I just want to use Qt library for some graphic displays. Does my dll need to be a QtProject?

              1>SynopticsWidget.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall SynopticsWidget::metaObject(void)const " (?metaObject@SynopticsWidget@@UBEPBUQMetaObject@@XZ)
              1>SynopticsWidget.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall SynopticsWidget::qt_metacast(char const *)" (?qt_metacast@SynopticsWidget@@UAEPAXPBD@Z)
              1>SynopticsWidget.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall SynopticsWidget::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@SynopticsWidget@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
              
              

              I'm stuck on that.
              Best,

              Massi

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

              @Massi If you don't use the plugin and qmake then you will need to handle moc by yourself.
              Please read the link I posted before: http://doc.qt.io/qt-5.8/moc.html
              There you can even find examples how to do it with make files.

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

              MassiM 1 Reply Last reply
              0
              • jsulmJ jsulm

                @Massi If you don't use the plugin and qmake then you will need to handle moc by yourself.
                Please read the link I posted before: http://doc.qt.io/qt-5.8/moc.html
                There you can even find examples how to do it with make files.

                MassiM Offline
                MassiM Offline
                Massi
                wrote on last edited by
                #7

                @jsulm Many Thanks! Finally it works! I had to handle moc by myself. However I also had to include the moc_Myfile.cpp files in to the solution and change its property Precompiled Header (right click to the project->Properties->C/C++->Precompiled Headers) to Not Using Precompiled Headers

                Thanks in advance!

                Massi

                Software Design Engineer at Ford - Canada

                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