QT 5.14.1 生成DLL和调用

1.创建一个DLL

 

 

 

 

 在文件testDLL.h修改

#ifndef TESTDLL_H
#define TESTDLL_H

#include "TestDll_global.h"

class TESTDLL_EXPORT TestDll
{
public:
    TestDll();
    int add(int a, int b);
};

#endif // TESTDLL_H

testDLL.cpp

#include "testdll.h"

TestDll::TestDll()
{
}

int TestDll::add(int a, int b)
{
    return a+b;
}

选择构建,生成

 2.dll的调用

新建一个控制台程序

 将testDLL.h以及testdll_dlobal.h拷贝到新建项目下

 修改配置文件,添加

HEADERS += \
    TestDll_global.h \
    testdll.h

 将生成的TestDll.dll复制到项目文件下

在.pro下配置lib所在路径

LIBS+=F:\Qt_workstation\testDLLok\TestDll.dll

修改main.cpp为

#include <QCoreApplication>
#include <testdll.h>
#include <TestDll_global.h>
#include <iostream>
using namespace std;
int main()
{
    //QCoreApplication a(argc, argv);

    //return a.exec();
    TestDll bb;
    int a = 10;
    int b = 15;
    int c = bb.add(a,b);
    cout<<c<<endl;
}

运行

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值