Results 1 to 5 of 5

Thread: Static linking against Qt 4.7.1 with microsoft compiler / linker.

  1. #1
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Static linking against Qt 4.7.1 with microsoft compiler / linker.

    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:
    Qt Code:
    1. 1>main.obj : warning LNK4217: locally defined symbol ??1QCoreApplication@@UAE@XZ (public: virtual __thiscall QCoreApplication::~QCoreApplication(void)) imported in function _main
    2. 1>main.obj : warning LNK4217: locally defined symbol ?exec@QCoreApplication@@SAHXZ (public: static int __cdecl QCoreApplication::exec(void)) imported in function _main
    3. 1>main.obj : warning LNK4217: locally defined symbol ?connect@QObject@@SA_NPBV1@PBD01W4ConnectionType@Qt@@@Z (public: static bool __cdecl QObject::connect(class QObject const *,char const *,class QObject const *,char const *,enum Qt::ConnectionType)) imported in function _main
    4. 1>main.obj : warning LNK4217: locally defined symbol ?qFlagLocation@@YAPBDPBD@Z (char const * __cdecl qFlagLocation(char const *)) imported in function _main
    5. 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(class QString const &)" (?processSharedMemoryBlock@OCRServerWorker@OCRS@@QAEXABVQString@@@Z)
    6. 1>main.obj : warning LNK4217: locally defined symbol ??0QCoreApplication@@QAE@AAHPAPAD@Z (public: __thiscall QCoreApplication::QCoreApplication(int &,char * *)) imported in function _main
    7. 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
    8. 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)
    9. 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)
    10. 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)
    11. [... Hundreds of lines like this ...]
    To copy to clipboard, switch view to plain text mode 

    Any help will greatly be appreciated

    Thanks a lot,
    Pierre.

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Static linking against Qt 4.7.1 with microsoft compiler / linker.

    Did QtNetwork get added properly to your library dependencies?
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Static linking against Qt 4.7.1 with microsoft compiler / linker.

    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/th...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.
    Last edited by d_stranz; 14th January 2011 at 16:26.

  4. #4
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Static linking against Qt 4.7.1 with microsoft compiler / linker.

    Quote Originally Posted by d_stranz View Post
    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.

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Static linking against Qt 4.7.1 with microsoft compiler / linker.

    Quote Originally Posted by hickscorp View Post
    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.

Similar Threads

  1. VC static linking lib with another lib
    By Mookie in forum General Programming
    Replies: 4
    Last Post: 23rd November 2010, 09:10
  2. Static linking with Qt
    By prykHetQuo in forum Qt Programming
    Replies: 3
    Last Post: 3rd June 2009, 21:56
  3. Static linking
    By didcea in forum Qt Programming
    Replies: 0
    Last Post: 11th October 2008, 19:40
  4. Qt 4.3 static linking on Windows
    By john_crichton in forum Installation and Deployment
    Replies: 2
    Last Post: 13th May 2008, 07:57
  5. gentoo qt4 static linking
    By powermax in forum Newbie
    Replies: 1
    Last Post: 27th April 2008, 22:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.