tags:

views:

335

answers:

2

I want to bring a .dll dependency into my Qt project.

So I added this to my .pro file:

win32 {
LIBS += C:\lib\dependency.lib
LIBS += C:\lib\dependency.dll
}

And then (I don't know if this is the right syntax or not)

#include <windows.h>
Q_DECL_IMPORT int WINAPI DoSomething();

btw the .dll looks something like this:

#include <windows.h>
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, 
                                        LPVOID lpReserved)
{
    return TRUE;
}

extern "C"
{
int WINAPI DoSomething() { return -1; }
};

Getting error: unresolved symbol?

Note: I'm not experienced with .dll's outside of .NET's ez pz assembly architechture, definitely a n00b.

+1  A: 

Your "LIBS +=" syntax is wrong. Try this:

win32 {
    LIBS += -LC:/lib/ -ldependency
}

I'm also not sure if having absolute paths with drive letter in your .pro file is a good idea - I usually keep the dependencies somewhere in the project tree and use relative path.

EDIT:

I suppose that something is wrong in your dll, i.e. the symbols are not exported correctly. I always use template provided by QtCreator:

  1. Inside dll project there is mydll_global.h header with code like that:

    #ifdef MYDLL_LIB
        #define MYDLL_EXPORT Q_DECL_EXPORT
    #else
        #define MYDLL_EXPORT Q_DECL_IMPORT
    #endif
    
  2. Dll project has DEFINES += MYDLL_LIB inside it's pro file.

  3. Exported class (or only selected methods) and free functions are marked with MYDLL_EXPORT inside header files, i.e.

    class MYDLL_EXPORT MyClass {
    
    
    // ...
    
    
    };
    
chalup
I did that and still get the undefined symbol error.
Bad Man
A: 

You need to make the function's declaration available to the linker as well as providing the path to the dll in which it's located. Usually this is done by #including a header file that contains the declaration.

You also don't need the Q_DECL_IMPORT macro in the client - this would be used in a Qt library's header to allow client apps to import the function. A class or function would be conditionally exported/imported depending on whether the library or a client is being built. More info can be found on this page.

Is your dependency a third party dll or something that you've created?

Stu Mackellar
If there was no header/missing include, there would be a compiler error, not linker error.
chalup
You didn't say whether it was a compiler or linker error or even which compiler you're using.
Stu Mackellar