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;
}
相关推荐
天下皆白_唯我独黑6 分钟前
php 使用qrcode制作二维码图片
开发语言·php
夜雨翦春韭10 分钟前
Java中的动态代理
java·开发语言·aop·动态代理
小远yyds11 分钟前
前端Web用户 token 持久化
开发语言·前端·javascript·vue.js
何曾参静谧24 分钟前
「C/C++」C/C++ 之 变量作用域详解
c语言·开发语言·c++
q567315231 小时前
在 Bash 中获取 Python 模块变量列
开发语言·python·bash
许野平1 小时前
Rust: 利用 chrono 库实现日期和字符串互相转换
开发语言·后端·rust·字符串·转换·日期·chrono
也无晴也无风雨1 小时前
在JS中, 0 == [0] 吗
开发语言·javascript
狂奔solar1 小时前
yelp数据集上识别潜在的热门商家
开发语言·python
blammmp2 小时前
Java:数据结构-枚举
java·开发语言·数据结构
何曾参静谧2 小时前
「C/C++」C/C++ 指针篇 之 指针运算
c语言·开发语言·c++