Qt5.14.2编译生成的.dll文件不能正常使用

我使用Qt5.14.2创建了一个名为mdll的共享库项目,用MinGW64bit编译,内容如下:
mdll.pro:

QT -= gui

TEMPLATE = lib
DEFINES += MDLL_LIBRARY

CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    mdll.cpp

HEADERS += \
    mdll_global.h \
    mdll.h

# Default rules for deployment.
unix {
    target.path = /usr/lib
}
!isEmpty(target.path): INSTALLS += target


mdll.h:

#ifndef MDLL_H
#define MDLL_H

#include "mdll_global.h"

class MDLL_EXPORT Mdll
{
public:
    Mdll();
    int triple(int _a);
};

#endif // MDLL_H


mdll_global.h:

#ifndef MDLL_GLOBAL_H
#define MDLL_GLOBAL_H

#include <QtCore/qglobal.h>

#if defined(MDLL_LIBRARY)
#  define MDLL_EXPORT Q_DECL_EXPORT
#else
#  define MDLL_EXPORT Q_DECL_IMPORT
#endif

#endif // MDLL_GLOBAL_H


mdll.cpp:

#include "mdll.h"

Mdll::Mdll()
{
}
int Mdll::triple(int _a)
{
    return _a*3;
}


然后我在我的另一个工程里引用的mdll项目生成的mdll.dll

QLibrary mylib("mdll");
    mylib.load();
    typedef int (*FunDef)(int); //需要声明函数原型的类型
    FunDef myTriple=(FunDef)mylib.resolve("triple");
    qDebug()<<myTriple(1);

结果程序异常结束。
我把"qDebug()<<myTriple(1);"这段代码去掉后能正常运行,mylib.isLoad()也输出true,但如果使用myTriple就会异常退出
并且我用dll解析器也不能正常分析这个生成的dll,说是格式未知
请问有人知道怎么解决吗

回答不易,求求您采纳点赞哦

听起来您遇到了 Qt5.14.2 编译的 .dll 文件无法正常工作的问题。

此问题有几个潜在原因:

  • .dll 文件可能不在应用程序找到它的正确位置。确保 .dll 文件位于正确的位置,并且应用程序也在正确的位置查找它。

  • .dll 文件可能缺少依赖项。确保所有必需的依赖项都存在并且位于正确的位置。

  • .dll 文件的版本与尝试使用它的应用程序的版本之间可能存在兼容性问题。确保 .dll 文件的版本与应用程序的版本兼容。

  • 您的代码可能存在导致 .dll 无法正常运行的错误。确保您的代码能够正确编译和运行。

  • 您使用的 MinGW64bit 可能与您使用的 Qt 版本不兼容。尝试使用不同版本的 MinGW 或不同的编译器。