将.dll导入Qt [英] Importing .dll into Qt

查看:231
本文介绍了将.dll导入Qt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给我的Qt项目带来一个.dll依赖。



所以我把它添加到我的.pro文件:

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

然后(我不知道这是否是正确的语法不)

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

btw .dll看起来像这样:

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

externC
{
int WINAPI DoSomething(){return -1; }
};

获取错误:未解决的符号?



注意:我没有经验的.dll的.NET的ez pz组件architechture,肯定是一个n00b。

解决方案

LIBS + =语法错误。尝试此操作:

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

我也不确定在.pro文件中是否有带驱动器号的绝对路径是一个好主意 - 我通常把依赖关系保存在项目树中的某个位置,并使用相对路径。



编辑:



你的dll中的东西是错误的,即符号不能正确导出。我总是使用由QtCreator提供的模板:


  1. 在dll项目中有mydll_global.h头文件, >

      #ifdef MYDLL_LIB 
    #define MYDLL_EXPORT Q_DECL_EXPORT
    #else
    #define MYDLL_EXPORT Q_DECL_IMPORT
    #endif


  2. Dll项目在其专业文件中有DEFINES + = MYDLL_LIB。


  3. 导出的类(或仅选定的方法)和自由函数在头文件中标有MYDLL_EXPORT,即

      class MYDLL_EXPORT MyClass {


    // ...


    };



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.

解决方案

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

这篇关于将.dll导入Qt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆