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;
}
相关推荐
从以前12 分钟前
【算法题解】Bindian 山丘信号问题(E. Bindian Signaling)
开发语言·python·算法
high201134 分钟前
【Java 基础】-- ArrayList 和 Linkedlist
java·开发语言
1nullptr37 分钟前
lua和C API库一些记录
开发语言·lua
Jerry Nan39 分钟前
Lua元表
开发语言·lua
?3333344 分钟前
CTFHub Web进阶-PHP-Bypass disable_function攻略
开发语言·安全·web安全·php
所以经济危机就是没有新技术拉动增长了1 小时前
二、javascript的进阶知识
开发语言·javascript·ecmascript
Bubluu1 小时前
浏览器点击视频裁剪当前帧,然后粘贴到页面
开发语言·javascript·音视频
AI人H哥会Java1 小时前
【Spring】基于XML的Spring容器配置——<bean>标签与属性解析
java·开发语言·spring boot·后端·架构
开心工作室_kaic1 小时前
springboot493基于java的美食信息推荐系统的设计与实现(论文+源码)_kaic
java·开发语言·美食