qt学习(八)动态库和静态库的实现和调用

动态库和静态库的实现和调用

1.新建->library->c++库,共享库,编写库的名称

#ifndef T14LIBRARY_H
#define T14LIBRARY_H

#include "t14library_global.h"

class T14LIBRARYSHARED_EXPORT T14Library
{

public:
    T14Library();

    void Encrypt();
};

#endif // T14LIBRARY_H
#ifndef T14LIBRARY_GLOBAL_H
#define T14LIBRARY_GLOBAL_H

#include <QtCore/qglobal.h>

#if defined(T14LIBRARY_LIBRARY)
#  define T14LIBRARYSHARED_EXPORT Q_DECL_EXPORT
#else
#  define T14LIBRARYSHARED_EXPORT Q_DECL_IMPORT
#endif

#endif // T14LIBRARY_GLOBAL_H
#include "t14library.h"
#include <QDebug>

T14Library::T14Library()
{
}


void T14Library::Encrypt()
{
    qDebug() << "Encrypt";;
}

2.新建一个项目调用库函数

SOURCES += 
    main.cpp

# 如果QT mingw版本,使用动态库方式和linux没区别(-L, -l)
# 如果QT VS版本。。。使用动态库方式和windows没区别
# 如果QT mingw版本,要调用VS写的动态库,使用一个工具,生成libXXXXX.a文件
LIBS += -LD:QTQT0718uild-T14Library-Desktop_Qt_5_3_0_MinGW_32bit-Debugdebug -lT14Library
#include <QCoreApplication>

#include "../T14Library/t14library.h"

int main(int argc, char* argv[])
{
    QCoreApplication app(argc, argv);

    T14Library d;
    d.Encrypt();

    app.exec();
}

3.静态库

1.新建->library->c++库,静态链接库,编写库的名称

原文地址:https://www.cnblogs.com/rainbow1122/p/8184099.html