PDA

View Full Version : Static linking against Qt 4.7.1 with microsoft compiler / linker.



hickscorp
14th January 2011, 03:30
Hello,

Because of some issues i had with a customer, i decided to link my applications as a static set of libraries. For this project, i'm working with Windows XP Pro, Qt 4.7.1 OpenSource and Visual Studio 2008 (With the VSAddIn). Therefore i have compiled Qt in a separated folder (C:/Qt/4.7.1/Static) by changing a few files in the mkspecs as explained in the Trolltech doc.

Then, i have changed my VS projects configuration to link against QtCore.lib / QtCoreb.lib instead of QtCore4.lib / QtCore4.lib, and so on for each required library (QtMain, QtCore, QtGui, QtNetwork, etc). i also have changed the runtimes for /MD in release and /MDd in debug.

One of my application compiles fine, and runs. Another one doesn't. The only difference i can see between those two is that the one not compiling links against QtNetwork, the other not.

Here comes my linker's log:
1>main.obj : warning LNK4217: locally defined symbol ??1QCoreApplication@@UAE@XZ (public: virtual __thiscall QCoreApplication::~QCoreApplication(void)) imported in function _main
1>main.obj : warning LNK4217: locally defined symbol ?exec@QCoreApplication@@SAHXZ (public: static int __cdecl QCoreApplication::exec(void)) imported in function _main
1>main.obj : warning LNK4217: locally defined symbol ?connect@QObject@@SA_NPBV1@PBD01W4ConnectionType@Q t@@@Z (public: static bool __cdecl QObject::connect(class QObject const *,char const *,class QObject const *,char const *,enum Qt::ConnectionType)) imported in function _main
1>main.obj : warning LNK4217: locally defined symbol ?qFlagLocation@@YAPBDPBD@Z (char const * __cdecl qFlagLocation(char const *)) imported in function _main
1>OCRServerWorker.obj : warning LNK4217: locally defined symbol ?qFlagLocation@@YAPBDPBD@Z (char const * __cdecl qFlagLocation(char const *)) imported in function "public: void __thiscall OCRS::OCRServerWorker::processSharedMemoryBlock(cl ass QString const &)" (?processSharedMemoryBlock@OCRServerWorker@OCRS@@Q AEXABVQString@@@Z)
1>main.obj : warning LNK4217: locally defined symbol ??0QCoreApplication@@QAE@AAHPAPAD@Z (public: __thiscall QCoreApplication::QCoreApplication(int &,char * *)) imported in function _main
1>main.obj : warning LNK4217: locally defined symbol ??1QTcpServer@@UAE@XZ (public: virtual __thiscall QTcpServer::~QTcpServer(void)) imported in function __unwindfunclet$??0OCRServer@OCRS@@QAE@PAVQObject@ @@Z$0
1>main.obj : warning LNK4217: locally defined symbol ??0QMutex@@QAE@W4RecursionMode@0@@Z (public: __thiscall QMutex::QMutex(enum QMutex::RecursionMode)) imported in function "public: __thiscall OCRS::OCRServer::OCRServer(class QObject *)" (??0OCRServer@OCRS@@QAE@PAVQObject@@@Z)
1>main.obj : warning LNK4217: locally defined symbol ??0QTcpServer@@QAE@PAVQObject@@@Z (public: __thiscall QTcpServer::QTcpServer(class QObject *)) imported in function "public: __thiscall OCRS::OCRServer::OCRServer(class QObject *)" (??0OCRServer@OCRS@@QAE@PAVQObject@@@Z)
1>main.obj : warning LNK4217: locally defined symbol ??1QHostAddress@@QAE@XZ (public: __thiscall QHostAddress::~QHostAddress(void)) imported in function "public: void __thiscall OCRS::OCRServer::start(void)" (?start@OCRServer@OCRS@@QAEXXZ)
[... Hundreds of lines like this ...]


Any help will greatly be appreciated :)

Thanks a lot,
Pierre.

franz
14th January 2011, 06:20
Did QtNetwork get added properly to your library dependencies?

d_stranz
14th January 2011, 15:21
Because of some issues i had with a customer, i decided to link my applications as a static set of libraries. For this project, i'm working with Windows XP Pro, Qt 4.7.1 OpenSource and Visual Studio 2008 (With the VSAddIn). Therefore i have compiled Qt in a separated folder (C:/Qt/4.7.1/Static) by changing a few files in the mkspecs as explained in the Trolltech doc.

I hope you are aware that the GNU LGPL and GPL licenses under which the open source versions of Qt are distributed do not permit you to link to static Qt libraries unless you also provide your source code (GPL) or object code (LGPL) so that the end user can rebuild the executable by either recompiling your source code or relinking your object code.

GPL requires you to distribute your source code. The liberal interpretation of the LGPL is that you could supply either source code or object code for your app, along with whatever changes you make to the Qt build files to create a static library so that the customer can build the static library and link your app's object code to it. However, the stricter interpretation that the Free Software Foundation prefers says that you must provide source code along with the build files if you are linking to a static build of an LGPL library.

There is a long discussion with many references here:

http://answers.google.com/answers/threadview/id/439136.html

And if you are being paid by your customer to develop this software, then do what I and many other commercial Qt developers do: Buy a Qt Commercial license. Then you can build and distribute your app in any form you want.

hickscorp
14th January 2011, 20:49
And if you are being paid by your customer to develop this software, then do what I and many other commercial Qt developers do: Buy a Qt Commercial license. Then you can build and distribute your app in any form you want.
The license is paid already, and i'm aware of each aspect of each license / sublicense. Thanks anyway.

@franz: Yes QNetwork is linked. Also, in the linker error log, you can see that not only references to QNetwork functions are being referenced, basically any Qt function are.

Any idea?
Thank you very much :)
Pierre.

d_stranz
14th January 2011, 23:44
The license is paid already, and i'm aware of each aspect of each license / sublicense. Thanks anyway.

OK, so then you aren't really using Qt 4.7.1 Open Source, you're using it under a commercial license and static linking is just fine.

Make sure you don't have QT_DLL defined in both the MSVC compile or link settings, and make sure you use the same compile settings for all of the libraries and app code. Sounds like maybe QtNetwork has different settings, and it might be trying to drag in QtCore classes and methods with the wrong mangled names.