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;
}
相关推荐
FL162386312940 分钟前
[深度学习][python]yolov11+bytetrack+pyqt5实现目标追踪
深度学习·qt·yolo
XKSYA(小巢校长)1 小时前
NatGo我的世界联机篇
开发语言·php
Cons.W1 小时前
Codeforces Round 975 (Div. 1) C. Tree Pruning
c语言·开发语言·剪枝
憧憬成为原神糕手1 小时前
c++_ 多态
开发语言·c++
VBA63371 小时前
VBA信息获取与处理第三个专题第三节:工作薄在空闲后自动关闭
开发语言
wjs20242 小时前
XSLT 实例:掌握 XML 转换的艺术
开发语言
萧鼎2 小时前
Python第三方库选择与使用陷阱避免
开发语言·python
安冬的码畜日常2 小时前
【D3.js in Action 3 精译_029】3.5 给 D3 条形图加注图表标签(上)
开发语言·前端·javascript·信息可视化·数据可视化·d3.js
一颗星星辰2 小时前
C语言 | 第十章 | 函数 作用域
c语言·开发语言
lxp1997412 小时前
php函数积累
开发语言·php