简体   繁体   中英

Qt5.0.1 static linking in Visual Studio 2012

I build Qt with a following configuration:

-platform win32-msvc2012 -no-icu -no-angle -opengl desktop -static -qt-sql-mysql -qt-plugins-mysql -nomake demos -nomake examples

and everything went fine. Btw. i also changed in qmake.conf for win32-msvc2012 mkspecs /MD to /MT for static linking (according to some instructions). Now i try to build the most simple application in Visual Studio 2012, using static linking. So i create simple project (this basic one, from Qt Visual Add-in) which is:

#include "test.h"
#include <QtWidgets/QApplication>

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

(test is just a plain window) and set two things which i remember since i was doing it on Visual Studio 2010: 1) Project properties -> C/C++ -> Code generation -> Runtime library i set to MT 2) Project properties -> General -> Use of MFC i set to Use MFC in a static library

Of cource in Qt project settings i have set my static version of Qt. In this configuration i'm getting so much errors – http://pastebin.com/6ve3pFUh [pastebin.com] All libs (i think that all) were added by Qt Add-in (qtmain.lib Qt5Core.lib Qt5Gui.lib Qt5Widgets.lib). If i set Use of MFC to default value which is Use standard Windows libraries then i'm getting this:

1>     Creating library D:\Visual Studio 11\Projects\test\Win32\Release\test.lib and object D:\Visual Studio 11\Projects\test\Win32\Release\test.exp
1>Qt5Core.lib(qeventdispatcher_win.obj) : error LNK2019: unresolved external symbol _WSAAsyncSelect@16 referenced in function "private: void __thiscall QEventDispatcherWin32::createInternalHwnd(void)" (?createInternalHwnd@QEventDispatcherWin32@@AAEXXZ)
1>D:\Visual Studio 11\Projects\test\Win32\Release\\test.exe : fatal error LNK1120: 1 unresolved externals

I totally have no idea what is going on. In Visual Studio 2010 and Qt 4.8 everything works perfectly fine this way. I read something about more external dependencies which i should add but i'm not sure about that. Ohh and by the way – in QtCreator this static linking works great, but it can't see MySQL plugin, which also is a mystery for me and i need it to my original project.

I am using Visual Studio 2013 but I noticed the exact same missing link yesterday.

You need to add a dependency to Ws2_32.lib.

If you project compile but crashes with a cryptic "windows platform plugin missing" message, you need to add this into one cpp:

Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);

This could add new dependencies.

FYI Those are the dependencies I use for a default Qt project (Some are only necessary with ANGLE):

  • winmm.lib
  • Ws2_32.lib
  • dxguid.lib
  • d3d9.lib
  • imm32.lib
  • qtmaind.lib
  • Qt5Cored.lib
  • Qt5Guid.lib
  • Qt5Widgetsd.lib
  • libEGLd.lib
  • libGL
  • ESv2d.lib
  • translator_commond.lib
  • preprocessord.lib
  • translator_hlsld.lib
  • qwindowsd.lib
  • Qt5PlatformSupportd.lib
  • %(AdditionalDependencies)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM