Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

So I added this to my .pro file:

win32 {
LIBS += C:libdependency.lib
LIBS += C:libdependency.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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
235 views
Welcome To Ask or Share your Answers For Others

1 Answer

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 {
    
    // ...
    
    };
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...