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. Linking QT Application to Visual Studio Static 32 bit library fails
Forum Updated to NodeBB v4.3 + New Features

Linking QT Application to Visual Studio Static 32 bit library fails

Scheduled Pinned Locked Moved Installation and Deployment
6 Posts 2 Posters 5.3k 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.
  • J Offline
    J Offline
    johnco3
    wrote on last edited by
    #1

    Hello All,

    I am trying to get up to speed with adding a new GUI front end to a previously console based application. The existing application was developed in Visual Studio 2012 Professional. The existing console application (executable) comprises a main() and about 20 or so static 32 bit libraries.

    I used the QT Creator (qt-windows-opensource-5.1.1-msvc2012_opengl-x86_64-offline & qt-vs-addin-1.2.2-opensource) to create a dummy application (using the built in QT Gui Application wizard) and then I choose the add library context popup to add one of these static libraries to the linker.

    Next I added a single line of code to use the generated main.cpp to bring in a reference from the static library and after qmaking and building the project, it complained as follows:

    @main.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl LoadsetList::LoadsetList(void)" (??0LoadsetList@@QEAA@XZ) referenced in function main
    main.obj:-1: error: LNK2019: unresolved external symbol "public: virtual __cdecl LoadsetList::~LoadsetList(void)" (??1LoadsetList@@UEAA@XZ) referenced in function main
    debug\vcbuild.exe:-1: error: LNK1120: 2 unresolved externals@

    Can anyone shed any light on what might be going wrong.

    Here is the project file (note that the include paths are setup to point to my existing source code for the static libraries and QT seems to recognize the code by auto-completion.
    @#-------------------------------------------------

    Project created by QtCreator 2013-10-29T17:27:49

    #-------------------------------------------------

    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = vcbuild
    TEMPLATE = app

    SOURCES += main.cpp
    mainwindow.cpp

    HEADERS += mainwindow.h

    INCLUDEPATH += /main/ltib/cpas/include
    /main/ltib/extlibs/pthreads-w32-2-8-0/include
    /main/ltib/extlibs/GnuWin32/include
    /main/ltib/sipXportLib/include

    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../ltib/cpas/win32/loadset/release/ -lloadset
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../ltib/cpas/win32/loadset/debug/ -lloadset

    INCLUDEPATH += $$PWD/../../ltib/cpas/win32/loadset/Debug
    DEPENDPATH += $$PWD/../../ltib/cpas/win32/loadset/Debug

    win32:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../ltib/cpas/win32/loadset/release/loadset.lib
    else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../ltib/cpas/win32/loadset/debug/loadset.lib
    @

    Here is the modified main.cpp: Note I simply put a single line referring to the LoadsetList object which resides in my static library

    @#include <QApplication>
    #include "mainwindow.h"
    #include "loadset/LoadsetList.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    LoadsetList loadsetList;
    return a.exec();
    }
    @

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

      Hi,

      I think the first problem you have is that you try to link 32bit libs to a 64bit Qt. You'll need to either use a 32bit Qt or a 64bit version of your libs

      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
      • J Offline
        J Offline
        johnco3
        wrote on last edited by
        #3

        Thanks, it looks like that seems to be the problem. I'm now facing having to port the existing code to x64. I noticed that in order to get the library to link correctly, I needed to create it as "Multi-threaded Debug DLL (/MDd)" - not doing so caused the following error:

        @error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug' in moc_mainwindow.obj
        @
        It looks like the autogenerated moc_mainwindow uses the /MDd build option and I need to match this. I'm not sure if there is some way of linking to my Static debug libraries - as my existing code is made up of libs and not DLLs.

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

          Not necessarily, you can also use a 32bit Qt. By default Qt is build against the dynamic runtime.

          You can also make your static library link against the dynamic runtime

          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
          • J Offline
            J Offline
            johnco3
            wrote on last edited by
            #5

            As posted above, I already tried to make the default 64 bit QT link with a test 64 bit static library which I set to use static debug output) - However, that failed with the LNK2038 indicated.

            Is there some QT (.pro) or Visual C++ project build setting I am missing in order to get the default 64 bit QT (which is built against the Dynamic run-time) to link with a static library like I have above?

            My only work around was to change the flags to match the QT's dynamic run-time). I would prefer not to recompile QT to static mode as I think that there are some licensing issues associated with that approach.

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

              AFAIK no, you have to use the same runtime linking. You could try to build Qt dynamically against the static runtime though (I don't know if it'll work) for that you need to edit the mkspec for your version of visual studio and replace all MDD occurrences with MTD

              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

              • Login

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