|
本帖最后由 Qter 于 2018-2-24 00:47 编辑
打开Qt Creator
1.创建解决方案
文件->新建文件或项目->其它项目->子目录项按向导(选择相关路径) ... 完成
即只生成一个 DoraemonSolution.pro文件 内容为:TEMPLATE = subdirs
2.创建主界面程序
右键 DoraemonSolution 新建子项目->Application->Qt Widgets Application
根据向导填写项目名称为 Doraemon
3.添加静态库QCommLib
右键 DoraemonSolution 新建子项目->Library->C++库
依赖库默认 QtCore
注意最后一步 默认做为子项目加入,如下:
4.Doraemon中添加对静态库QCommLib的依赖
右键 Doraemon ->添加库-> 内部库
下一步后,将在Doraemon.pro文件添加如下代码
- win32:CONFIG(release, debug|release): LIBS += -L$OUT_PWD/../QCommLib/release/ -lQCommLib
- else:win32:CONFIG(debug, debug|release): LIBS += -L$OUT_PWD/../QCommLib/debug/ -lQCommLib
- else:unix: LIBS += -L$OUT_PWD/../QCommLib/ -lQCommLib
- INCLUDEPATH += $PWD/../QCommLib
- DEPENDPATH += $PWD/../QCommLib
- win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $OUT_PWD/../QCommLib/release/libQCommLib.a
复制代码 调用时直接包含相关库中的头文件(如:#include "qcommlib.h" ),就可以调用了
5.添加动态库QControlSo
右键 DoraemonSolution 新建子项目->Library->C++库
共享 库 多了文件 qcontrolso_global.h- #ifndef QCONTROLSO_GLOBAL_H
- #define QCONTROLSO_GLOBAL_H
- #include <QtCore/qglobal.h>
- #if defined(QCONTROLSO_LIBRARY)
- # define QCONTROLSOSHARED_EXPORT Q_DECL_EXPORT
- #else
- # define QCONTROLSOSHARED_EXPORT Q_DECL_IMPORT
- #endif
- #endif // QCONTROLSO_GLOBAL_H
复制代码 宏的相关定义,如下:- # ifdef Q_OS_WIN
- # define Q_DECL_EXPORT __declspec(dllexport)
- # define Q_DECL_IMPORT __declspec(dllimport)
- # elif defined(QT_VISIBILITY_AVAILABLE)
- # define Q_DECL_EXPORT __attribute__((visibility("default")))
- # define Q_DECL_IMPORT __attribute__((visibility("default")))
- # define Q_DECL_HIDDEN __attribute__((visibility("hidden")))
- # endif
复制代码 6.Doraemon中添加对共享库QControlSo的依赖
右键 Doraemon ->添加库-> 内部库
下一步后,将在Doraemon.pro文件添加如下代码- win32:CONFIG(release, debug|release): LIBS += -L$OUT_PWD/../QControlSo/release/ -lQControlSo
- else:win32:CONFIG(debug, debug|release): LIBS += -L$OUT_PWD/../QControlSo/debug/ -lQControlSo
- else:unix: LIBS += -L$OUT_PWD/../QControlSo/ -lQControlSo
- INCLUDEPATH += $PWD/../QControlSo
- DEPENDPATH += $PWD/../QControlSo
复制代码 |
|