Results 1 to 6 of 6

Thread: Statically linking third party dll(no .lib file) and use classes using qt

  1. #1
    Join Date
    Jul 2012
    Posts
    3
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question Statically linking third party dll(no .lib file) and use classes using qt

    Hi,

    I am using third party .dll in my application. I have only .dll (neither .lib file nor header file). I am unable to use namespaces in application. which are present in that dll.

    Please help me out.

    Thanks in advance.
    Rachana K

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Statically linking third party dll(no .lib file) and use classes using qt

    If you don't have headers then you can only runtime load the library and resolve C functions by name.
    There are no namespaces in C.

    Cheers,
    _

  3. #3
    Join Date
    Jul 2012
    Posts
    3
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Exclamation Re: Statically linking third party dll(no .lib file) and use classes using qt

    Hi,

    I need to use classes in my application, That's why i need statically linking to application.

    Thanks for reply

  4. #4
    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: Statically linking third party dll(no .lib file) and use classes using qt

    The ability to use classes in an application has absolutely no relationship to whether those classes are implemented in a dynamic or a static library.

    In Windows, you cannot force static linking to a dynamic library. When Windows creates a library of any sort that contains C++ classes, the names are "mangled" - extra information is added to the class and member function names to tell the linker how to resolve the class, function, and variable types at runtime. In addition, classes and methods defined in a DLL may be for internal use in the DLL; if they are not exported, then they cannot be used from outside the DLL.

    The purpose of the header file and the .lib file (the "export library") is to tell the compiler and linker which classes and methods are exported, and how to create placeholders in the linked executable so that the DLL can be loaded at runtime and the actual locations of the exported functions linked into the runtime symbol table.

    So unless you know how to "unmangle" the exported class and method names, you will not be able to use them in an application without also having a header file and export library. Microsoft's "dumpbin" program will tell you what is exported from the DLL, but only as mangled names.

    The only way to use the DLL without linking against an export library is to use the Windows "LoadLibrary" method (or the Qt equivalent, QLibrary::load()) and ask for the exported function pointers using the mangled names.

    You will still have to figure out how to properly use the classes and methods, including which arguments and types to pass when making method calls.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Jul 2012
    Posts
    3
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Statically linking third party dll(no .lib file) and use classes using qt

    Hi,

    Actually same dll file is properly working in visual studio. Required classes are exported and used in that application just by using namespace and adding reference of that dll file.
    So I need to use same dll in qt application. I have linked that dll in my application but still unable to use namespace.
    Is header file required for using namespace and using classes in application ?


    Thanks for help.

  6. #6
    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: Statically linking third party dll(no .lib file) and use classes using qt

    Is your DLL a COM DLL? Then you need to #import the type library into your app. Is your VS project a .Net app? That's what adding the reference in VS is doing for you behind the scenes.

    You still cannot link to it statically. It's a DLL. Your VS app is loading it at runtime even if you don't think so. Build your app, then move the DLL somewhere (or rename it temporarily), then run your app without rebuilding. It will tell you it can't find the DLL.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Linking with third-party libraries
    By blooglet in forum Newbie
    Replies: 2
    Last Post: 22nd December 2011, 11:26
  2. Replies: 3
    Last Post: 28th June 2011, 19:32
  3. linking to 3rd party windows DLL
    By shan in forum Newbie
    Replies: 2
    Last Post: 29th January 2011, 11:51
  4. Linking 3rd party libs on Mac OS X
    By jonks in forum Qt Programming
    Replies: 2
    Last Post: 21st June 2010, 07:03
  5. Linking Third party Libraries
    By jsmith in forum Qt Programming
    Replies: 1
    Last Post: 13th October 2009, 07:18

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.