Qt生成动态库

cpp 复制代码
#-------------------------------------------------
#
# Project created by QtCreator 2023-11-12T09:49:23
#
#-------------------------------------------------

QT       += gui

TARGET = CLibrary
TEMPLATE = lib

DEFINES += LIBRARY_LIBRARY

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as 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

win32
{
    #动态库生成路径配置
    CONFIG(release, debug|release){
        DESTDIR = $$PWD/bin/release
    }else{
        TARGET = $$join(TARGET,,,d)   #为debug版本生成的文件增加d的后缀
        DESTDIR = $$PWD/bin/debug
    }
}

#Specifies the #include directories which should be searched when compiling the project
# ./ 也有用
INCLUDEPATH += \
    ./include/

# You can also make your code fail to compile if you use 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

HEADERS += \
        include/clibrary.h \
    include/library_global.h

SOURCES += \
        clibrary.cpp


unix {
    target.path = /usr/lib
    INSTALLS += target
}
cpp 复制代码
#ifndef LIBRARY_GLOBAL_H
#define LIBRARY_GLOBAL_H

#include <QtCore/qglobal.h>

#if defined(LIBRARY_LIBRARY)
#  define LIBRARYSHARED_EXPORT Q_DECL_EXPORT
#else
#  define LIBRARYSHARED_EXPORT Q_DECL_IMPORT
#endif

#endif // LIBRARY_GLOBAL_H
cpp 复制代码
#ifndef CLIBRARY_H
#define CLIBRARY_H

#include "library_global.h"

class LIBRARYSHARED_EXPORT CLibrary
{

public:
    CLibrary();
    int add(const int &a, const int &b);
};

#endif // CLIBRARY_H
cpp 复制代码
#include "clibrary.h"


CLibrary::CLibrary()
{
}

int CLibrary::add(const int &a, const int &b)
{
    return a + b;
}
相关推荐
ftpeak22 分钟前
JavaScript性能优化实战
开发语言·javascript·性能优化
一个很帅的帅哥1 小时前
JavaScript事件循环
开发语言·前端·javascript
驰羽1 小时前
[GO]gin框架:ShouldBindJSON与其他常见绑定方法
开发语言·golang·gin
程序员大雄学编程1 小时前
「用Python来学微积分」5. 曲线的极坐标方程
开发语言·python·微积分
Jose_lz2 小时前
C#开发学习杂笔(更新中)
开发语言·学习·c#
QT 小鲜肉2 小时前
【个人成长笔记】Qt 中 SkipEmptyParts 编译错误解决方案及版本兼容性指南
数据库·c++·笔记·qt·学习·学习方法
OneSea2 小时前
Debian编译Qt5
linux·qt
一位代码2 小时前
python | requests爬虫如何正确获取网页编码?
开发语言·爬虫·python
看到我,请让我去学习2 小时前
Qt 控件 QSS 样式大全(通用属性篇)
开发语言·c++·qt
筱砚.2 小时前
【STL——vector容器】
开发语言·c++