Import .dll into Qt

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 correct syntax or not)

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

btw.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 character?

Note. I am not experiencing problems with .dll outside of .NET ez pz assembly architchture, specifically n00b.

+3
source share
3 answers

The syntax "LIBS + =" is invalid. Try the following:

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

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

EDIT:

, - DLL, . , QtCreator:

  • dll mydll_global.h :

    #ifdef MYDLL_LIB
        #define MYDLL_EXPORT Q_DECL_EXPORT
    #else
        #define MYDLL_EXPORT Q_DECL_IMPORT
    #endif
    
  • Dll DEFINES + = MYDLL_LIB pro.

  • ( ) MYDLL_EXPORT , ..

    class MYDLL_EXPORT MyClass {
    
    // ...
    
    };
    
+6

, DLL "C" (.. ++), .def DLL. .def, , http://www.dependencywalker.com/, ; , . mylibname.def, :

LIBRARY mylibname

EXPORTS
    FirstExportedFunctionName
    SecondExportedFunctionName
    ...
    LastExpertedFunctionName

dlltool ( MinGW\bin):

dlltool -d mylibname.def -l mylibname.a

mylibname.a, .pro :

win32:LIBS += mylibname.a

, .

, DLL, , Q_DECL_IMPORT. .h :

extern "C" {
MYLIBAPI(retType) FirstFunctionName(arg list...);
MYLIBAPI(retType) SecondFunctionName(arg list...);
...
MYLIBAPI(retType) LastFunctionName(arg list...);
}

MYLIBAPI

#define MYLIBAPI(retType) Q_DECL_IMPORT retType

MYLIBAPI (retType), , DLL, .

, QT MinGW DLL, VS 2005. VS __stdcall. dlltool .

+2

, DLL, . #, , .

Q_DECL_IMPORT - Qt, . / , . .

dll -, ?

0

Source: https://habr.com/ru/post/1740105/


All Articles