当前位置:网站首页>Qt 动态库与静态库
Qt 动态库与静态库
2022-07-30 15:38:00 【陈子青 - See】
动态库的生成
使一个项目编译生成DLL库而不生成可执行文件:
删除main()函数;
将.pro项目文件中的TEMPLATE = app改为TEMPLATE = lib。
然后编译,此时生成的就是.a和.dll的文件。
动态库的使用
在另一个项目中调用此DLL:
在项目文件中添加LIB。如添加此行:LIBS += "D:/workspace/MRP_Common/debug/common.dll" (common.dll既是上面生成的DLL);
复制dll中类或方法的头文件到该项目中,并在要调用common.dll中类或方法的文件上面include;
make,在debug目录中生成可执行文件,然后将dll复制到debug中,运行。
静态库的生成
1. 测试目录: lib
2. 源码文件名: mywindow.h, mywindow.cpp, 类MyWindow继承于QPushButton, 并将文字设置为"I'm in class MyWindow";
3. 编写项目文件: mywindow.pro
注意两点:
TEMPLATE = lib
CONFIG += staticlib
4. 生成Makefile:
qmake
5. 编译生成静态库libmywindow.a
make
静态库的使用
1. 测试目录: test
2. 将mywindow.h与libmywindow.a拷贝至test目录下
3. 编写main.cpp, 包含头文件mywindow.h, 并调用MyWindow类
4. 编写项目文件: test.pro
注意加上库路径与库文件名:
LIBS += -L ./ -lmywindow
5. 生成Makefile: qmake
6. 编译: make
7. 运行: ./test
边栏推荐
- 服务器装好系统的电脑怎么分区
- [HMS core] [FAQ] Collection of typical problems of push kit, AR Engine, advertising service, scanning service 2
- TiDB 工具适用场景
- tiup env
- L2-007 Family property (use of vector, set, map)
- 华为「天才少年」计划招募的博士们,迎来首秀!
- MySql 和 PostgreSQL 数据库 根据一张表update另一张表数据
- tiup help
- 应用接入华为分析在应用调试模式下为何没有数据上报?
- php如何查询字符串出现位置
猜你喜欢
Redis 复习计划 - Redis 数据结构和持久化机制
How to intercept the first few digits of a string in php
影像信息提取DEM
Classes and Objects (Part 2)
Flask入门学习教程
rscsa笔记八
Why is there no data reported when the application is connected to Huawei Analytics in the application debugging mode?
php如何去除字符串最后一位字符
经典实例分割模型Mask RCNN原理与测试
HTTP缓存小结
随机推荐
TiDB 工具适用场景
【C语言】指针和数组的深入理解(第二期)
华为「天才少年」计划招募的博士们,迎来首秀!
Core Topics under Microservice Architecture (2): Design Principles and Core Topics of Microservice Architecture
【HMS core】【FAQ】Account、IAP、Location Kit and HarmonyOS典型问题合集1
arcpy使用教程
tiup completion
How to intercept the first few digits of a string in php
Changing SELECT...FROM to FROM...SELECT doesn't 'fix' SQL
ECCV2022 | FPN错位对齐,实现高效半监督目标检测 (PseCo)
481-82 (105, 24, 82, 34, 153),
rhce笔记1
[HMS core] [FAQ] A collection of typical questions about push kit, analysis services, and video editing services 3
yarn的安装及使用教程
为什么数据需要序列化
TiUP 术语及核心概念
TiUP FAQ
TiDB 工具功能概览
RISC-V调用惯例
AI遮天传 DL-CNN