+ Reply to Thread
Results 1 to 3 of 3

Thread: Linking to a windows DLL from Qt Creator on Windows

  1. #1
    Join Date
    Nov 2009
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Linking to a windows DLL from Qt Creator on Windows

    I have built an app in Qt Creator on Windows, and it builds and runs correctly.

    I have received header, .lib and .dll from a vendor built with Visual Studio on Windows. I would like to link to to their libraries. I do not have access to their source code.

    I'm using the g++ toolset and fail at link time (exported symbols, I assume). The vendor's VendorClass.h, VendorClass.lib and VendorClass.dll are all in "C:/Program Files/VendorTools/lib"

    My .pro file has
    Qt Code:
    1. INCLUDEPATH += "C:/Program Files/VendorTools/lib"
    2. LIBS += -L"C:/Program Files/VendorTools/lib" -lVendorClass
    To copy to clipboard, switch view to plain text mode 

    I edit the vendor's header file so that it reads:
    Qt Code:
    1. class Q_DECL_IMPORT VendorClass
    2. {
    3. public:
    4. VendorClass();
    5. }
    To copy to clipboard, switch view to plain text mode 

    (I've also tried declaring the class with __declspec(dllimport) ), same results.

    Error is something like:
    undefined reference to '__imp___ZN5VendorClassC1ERKSs'
    dumpbin /linkermember VendorClass.lib shows a decorated class name that differs from the linker error I get from Qt.

    How do I properly declare and compile a class so that it will link to a VC2008-compiled .lib for a .dll? Or is there a compiler flag that is required for properly using a Windows dll.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 345 Times in 332 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Linking to a windows DLL from Qt Creator on Windows

    G++ uses different name decoration than Visual studio, so by default DLL files generated by Visual studio are not compatible with G++. They also has different runtime libraries and possibly even different ABI's.

    If it was a C library, you can sometimes link against it with some tweaking, but being C++ presents a nightmare. You can create a shunt between the two interfaces, but thats not exactly easy.

    Sometimes even a different version of the compiler isn't compatible with a DLL from a vendor, which is why they typically distribute the library for the different versions available.

    This is why Microsoft use COM to access the C++ classes within Windows. It bypasses all of this and so you end with it not caring about the compiler, version, mangling type, etc.

    By far the easiest way of using the library is to use the same version of Visual Studio that the vendor used.

  3. The following user says thank you to squidge for this useful post:

    barryhf (25th November 2009)

  4. #3
    Join Date
    Nov 2009
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Linking to a windows DLL from Qt Creator on Windows

    Thank you for the basic answer.

    Another newbie follow-up: Is there a FAQ for configuring Qt Creator to use the Visual Studio compilers (which I have installed)?

+ Reply to Thread

Similar Threads

  1. jom / Windows SDK libs linking problem
    By nooky59 in forum Qt Tools
    Replies: 3
    Last Post: 12th November 2009, 14:58
  2. Linking to a static library on Windows
    By rexi in forum Qt Programming
    Replies: 9
    Last Post: 27th July 2009, 19:54
  3. Linking problems with QT4 under Windows
    By Ancalagon in forum Qt Programming
    Replies: 2
    Last Post: 8th September 2008, 13:29
  4. Link errors when linking chained libraries on windows
    By darkadept in forum Qt Programming
    Replies: 5
    Last Post: 26th May 2008, 14:52
  5. Qt 4.3 static linking on Windows
    By john_crichton in forum Installation and Deployment
    Replies: 2
    Last Post: 13th May 2008, 06:57

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