官术网_书友最值得收藏!

cm-lib

First off, head to file explorer and create a new subfolder underneath cm-lib called source; move cm-lib_global.h there. Create another subfolder in source called models and move both the Client class files there.

Next, back in Qt Creator, open up cm-lib.pro and edit it as follows:

QT -= gui
TARGET = cm-lib TEMPLATE = lib
CONFIG += c++14
DEFINES += CMLIB_LIBRARY
INCLUDEPATH += source
SOURCES += source/models/client.cpp
HEADERS += source/cm-lib_global.h \ source/models/client.h

As this is a library project, we do not need to load the default GUI module, so we exclude it using the QT variable. The TARGET variable is the name we wish to give our binary output (for example, cm-lib.dll). It is optional and will default to the project name if not provided, but we’ll be explicit. Next, rather than having a TEMPLATE of app as we saw in our scratchpad application, this time we use lib to give us a library. We add c++14 features via the CONFIG variable.

The cm-lib_global.h file is a helpful little bit of preprocessor boilerplate we can use to export our shared library symbols, and you’ll see that put to use soon. We use the CMLIB_LIBRARY flag in the DEFINES variable to trigger this export.

Finally, we have slightly rewritten the SOURCES and HEADERS variable lists to account for the new file locations after we moved things around a bit, and we add the source folder (which is where all of our code will live) to the INCLUDEPATH so that the path is searched when we use #include statements.

Right-click on the cm-lib folder in the Projects pane and select Run qmake. When that has finished, right-click again and select Rebuild. Everything should be green and happy.

主站蜘蛛池模板: 霍林郭勒市| 筠连县| 孝昌县| 东源县| 白城市| 云安县| 文化| 镇沅| 乃东县| 宝应县| 苍南县| 白河县| 保亭| 丹东市| 兴山县| 皮山县| 天柱县| 社旗县| 留坝县| 介休市| 庄浪县| 哈密市| 会宁县| 徐汇区| 平谷区| 辛集市| 资阳市| 濉溪县| 连云港市| 江川县| 宿松县| 漠河县| 洛川县| 贞丰县| 蓬安县| 德州市| 光山县| 泸溪县| 沾益县| 天镇县| 喀喇沁旗|