新建动态库的流程一样,只不过少了对外接口导出文件
构建目录也不要用默认的,通过.pro文件设置生成库的路径
代码和Qt创建和调用动态链接库-1的库的代码一致.pro的内容也一样
调用动态链接库
将对外的头文件复制到可以访问的路径,我这边是复制到Debug路径下,库文件也在这个路径下,将来的exe文件也在这个路径下
调用库的方式,选择“添加库...”
选择“外部库”
后面就一直默认下一步
.cpp
#include "Demo.h"
#include "ui_Demo.h"
#include <QDebug>
#include "../Debug/MyDll.h"
CDemo::CDemo(QWidget *parent)
: QDialog(parent)
, ui(new Ui::CDemo)
{
ui->setupUi(this);
CMyDll test;
test.MyActive();
}
CDemo::~CDemo()
{
delete ui;
}
.pro,可以不同的Qt编译器配置的不一样
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
Demo.cpp
HEADERS += \
Demo.h
FORMS += \
Demo.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../release/ -lMyDll
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../debug/ -lMyDll
INCLUDEPATH += $$PWD/../Debug
DEPENDPATH += $$PWD/../Debug