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;
}
相关推荐
深耕AI4 分钟前
【 从零开始的VS Code Python环境配置:uv】
开发语言·python·uv
AI_56786 分钟前
RabbitMQ消息队列:高可用集群搭建与消息幂等处理
开发语言·后端·ruby
艾莉丝努力练剑7 分钟前
【QT】常用控件(一):初识控件,熟悉QWidget
android·linux·数据库·qt·学习·mysql·qt5
古城小栈10 分钟前
Rust 1.94.0 闪亮登台
开发语言·后端·rust
SEO-狼术13 分钟前
Convert HTML Tables to PDF in Python
开发语言·python·pdf
码云数智-大飞13 分钟前
三足鼎立下的抉择:深度解析 Vue、React 与 Angular 的核心差异与选型指南
开发语言
娇娇yyyyyy16 分钟前
QT编程(5):几种常用的对话框
windows·qt·microsoft
TheLegendMe18 分钟前
Python 基础语法练习题
开发语言·python
格林威19 分钟前
工业相机图像高速存储(C#版):内存映射文件方法,附海康相机C#实战代码!
开发语言·人工智能·数码相机·opencv·计算机视觉·c#·工业相机
csbysj202019 分钟前
Lua 数据库访问
开发语言