PDA

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



RachanaKalaskar
3rd October 2016, 08:18
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

anda_skoa
3rd October 2016, 09:47
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,
_

RachanaKalaskar
3rd October 2016, 10:21
Hi,

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

Thanks for reply

d_stranz
3rd October 2016, 18:28
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.

RachanaKalaskar
4th October 2016, 05:41
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.

d_stranz
4th October 2016, 18:04
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.