使用qt版本windows qt5.12.0。
目的:为了调试qmake代码,深入理解qmake代码逻辑,了解qmake实现细节,以及了解qt文档中未提及或提及但不清楚的关于qmake language的CONFIG参数、变量、内置变量、代码逻辑 和 内置函数。
有关qmake language的词法、语法、内置函数:qmake language_丘上人的博客-CSDN博客
qmake最终产物是Makefile或windows下的vs工程文件,qmake主要作用是为跨平台和跨编译工具提供环境配置支持(这一点就非常契合qt的目的),其跨平台支持的工作都在QtInstallDir\Qt5.12.0\5.12.0\msvc2015_64\mkspecs之中。qmake 提供qmake langueage及其内置函数 支持。另外qmake结合qtcreator共同组成完善的可视化工程代码维护和编辑工具,方便开发工作,简易化操作。
qmake是作为qt的模块一起放在qt的源文件中。qt工程为编译qmake提供了编译方案。但这里没有用qt工程中提供的编译qmake方案。
qmake的源码与qt库的源码文件是有共用的,但需要通过开启宏开关QT_BOOTSTRAPPED和QT_BUILD_QMAKE来控制代码使用。编译qt工程,不能依赖qt库,因为两者有头文件是共用的,会导致编译冲突!所以可以看到qmake.pro中有“CONFIG -= qt”,这表示不依赖qt库,这样可以看到qmake工程生成的Makefile.Debug中的LIBS项中没有qt相关的库文件。
我编译qmake是直接拷贝原始QtInstallDir\Qt5.12.0\5.12.0\Src\qtbase\qmake路径下的工程到E:\workspace\QtWork\qmake,并通过qmake.pro链接了部分QtInstallDir\Qt5.12.0\5.12.0\Src\qtbase下的代码。下面是一个在我电脑上完整可用的已被我修改的qmake.pro文件(可以用beyongcompare与原始qmake.pro进行对比)及自己手写的config.cpp文件:
- # This project is not actually used to build qmake, but to support development
- # with Qt Creator. The real build system is made up by the Makefile templates
- # and the configures.
-
- option(host_build)
- CONFIG += console
- CONFIG -= qt app_bundle
-
- DEFINES += \
- PROEVALUATOR_FULL \
- QT_BOOTSTRAPPED \
- QT_BUILD_QMAKE \
- QT_NO_FOREACH \
- $$shell_quote(QT_VERSION_STR=\"$$QT_VERSION\") \
- QT_VERSION_MAJOR=$$QT_MAJOR_VERSION \
- QT_VERSION_MINOR=$$QT_MINOR_VERSION \
- QT_VERSION_PATCH=$$QT_PATCH_VERSION
-
- win32: DEFINES += \
- UNICODE \
- _ENABLE_EXTENDED_ALIGNED_STORAGE \
- _CRT_SECURE_NO_WARNINGS _SCL_SECURE_NO_WARNINGS
-
- # qmake code
-
- PRECOMPILED_HEADER += qmake_pch.h
-
- INCLUDEPATH += \
- . \
- library \
- generators \
- generators/unix \
- generators/win32 \
- generators/mac
-
- SOURCES += \
- main.cpp \
- meta.cpp \
- option.cpp \
- project.cpp \
- property.cpp \
- library/ioutils.cpp \
- library/proitems.cpp \
- library/qmakebuiltins.cpp \
- library/qmakeevaluator.cpp \
- library/qmakeglobals.cpp \
- library/qmakeparser.cpp \
- library/qmakevfs.cpp \
- generators/makefile.cpp \
- generators/makefiledeps.cpp \
- generators/metamakefile.cpp \
- generators/projectgenerator.cpp \
- generators/xmloutput.cpp \
- generators/mac/pbuilder_pbx.cpp \
- generators/unix/unixmake.cpp \
- generators/unix/unixmake2.cpp \
- generators/win32/mingw_make.cpp \
- generators/win32/msbuild_objectmodel.cpp \
- generators/win32/msvc_nmake.cpp \
- generators/win32/msvc_objectmodel.cpp \
- generators/win32/msvc_vcproj.cpp \
- generators/win32/msvc_vcxproj.cpp \
- generators/win32/winmakefile.cpp
-
- HEADERS += \
- cachekeys.h \
- meta.h \
- option.h \
- project.h \
- property.h \
- library/ioutils.h \
- library/proitems.h \
- library/qmake_global.h \
- library/qmakeevaluator.h \
- library/qmakeevaluator_p.h \
- library/qmakeglobals.h \
- library/qmakeparser.h \
- library/qmakevfs.h \
- generators/makefile.h \
- generators/makefiledeps.h \
- generators/metamakefile.h \
- generators/projectgenerator.h \
- generators/xmloutput.h \
- generators/mac/pbuilder_pbx.h \
- generators/unix/unixmake.h \
- generators/win32/mingw_make.h \
- generators/win32/msbuild_objectmodel.h \
- generators/win32/msvc_nmake.h \
- generators/win32/msvc_objectmodel.h \
- generators/win32/msvc_vcproj.h \
- generators/win32/msvc_vcxproj.h \
- generators/win32/winmakefile.h
-
- # qt code
-
- bp = D:/Qt/Qt5.12.0/5.12.0/Src/qtbase #$$shadowed(..)
- INCLUDEPATH += \
- $$bp/include $$bp/include/QtCore \
- $$bp/include/QtCore/$$QT_VERSION $$bp/include/QtCore/$$QT_VERSION/QtCore \
- $$bp/src/corelib/global
-
- VPATH += \
- $$bp/src/corelib/global \
- $$bp/src/corelib/tools \
- $$bp/src/corelib/kernel \
- $$bp/src/corelib/codecs \
- $$bp/src/corelib/plugin \
- $$bp/src/corelib/io \
- $$bp/src/corelib/serialization
-
- SOURCES += \
- qabstractfileengine.cpp \
- qarraydata.cpp \
- qbitarray.cpp \
- qbuffer.cpp \
- qbytearray.cpp \
- qbytearraymatcher.cpp \
- qcryptographichash.cpp \
- qdatetime.cpp \
- qdir.cpp \
- qdiriterator.cpp \
- qfile.cpp \
- qfiledevice.cpp \
- qfileinfo.cpp \
- qfilesystemengine.cpp \
- qfilesystementry.cpp \
- qfsfileengine.cpp \
- qfsfileengine_iterator.cpp \
- qglobal.cpp \
- qhash.cpp \
- qiodevice.cpp \
- qjson.cpp \
- qjsonarray.cpp \
- qjsondocument.cpp \
- qjsonobject.cpp \
- qjsonparser.cpp \
- qjsonvalue.cpp \
- qlibraryinfo.cpp \
- qlinkedlist.cpp \
- qlist.cpp \
- qlocale.cpp \
- qlocale_tools.cpp \
- qlogging.cpp \
- qmalloc.cpp \
- qmap.cpp \
- qmetatype.cpp \
- qnumeric.cpp \
- qregexp.cpp \
- qsettings.cpp \
- qstring.cpp \
- qstring_compat.cpp \
- qstringlist.cpp \
- qsystemerror.cpp \
- qtemporaryfile.cpp \
- qtextcodec.cpp \
- qtextstream.cpp \
- qutfcodec.cpp \
- quuid.cpp \
- qvariant.cpp \
- qversionnumber.cpp \
- qvsnprintf.cpp \
- qxmlstream.cpp \
- qxmlutils.cpp \
- qdebug.cpp \
- qringbuffer.cpp \
- qoperatingsystemversion.cpp \
- qrandom.cpp \
- qendian.cpp
-
- HEADERS += \
- qabstractfileengine_p.h \
- qarraydata.h \
- qarraydataops.h \
- qarraydatapointer.h \
- qbitarray.h \
- qbuffer.h \
- qbytearray.h \
- qbytearraymatcher.h \
- qchar.h \
- qcryptographichash.h \
- qdatetime.h \
- qdatetime_p.h \
- qdir.h \
- qdir_p.h \
- qdiriterator.h \
- qfile.h \
- qfileinfo.h \
- qglobal.h \
- qhash.h \
- qiodevice.h \
- qjson.h \
- qjsonarray.h \
- qjsondocument.h \
- qjsonobject.h \
- qjsonparser.h \
- qjsonvalue.h \
- qjsonwriter.h \
- qlinkedlist.h \
- qlist.h \
- qlocale.h \
- qlocale_tools_p.h \
- qmalloc.h \
- qmap.h \
- qmetatype.h \
- qnumeric.h \
- qregexp.h \
- qstring.h \
- qstringlist.h \
- qstringmatcher.h \
- qsystemerror_p.h \
- qtemporaryfile.h \
- qtextcodec.h \
- qtextstream.h \
- qutfcodec.h \
- quuid.h \
- qvector.h \
- qversionnumber.h \
- qxmlstream.h \
- qxmlutils.h \
- qdebug_p.h \
- qiodevice_p.h \
- qringbuffer_p.h \
- qoperatingsystemversion.h \
- qrandom.h \
- qendian.h
-
- unix {
- SOURCES += \
- qcore_unix.cpp \
- qfilesystemengine_unix.cpp \
- qfilesystemiterator_unix.cpp \
- qfsfileengine_unix.cpp \
- qlocale_unix.cpp
- macos {
- SOURCES += \
- qcore_foundation.mm \
- qcore_mac.cpp \
- qoperatingsystemversion_darwin.mm \
- qsettings_mac.cpp
- LIBS += \
- -framework ApplicationServices \
- -framework CoreServices \
- -framework Foundation
- QMAKE_CXXFLAGS += -fconstant-cfstrings
- }
- } else {
- SOURCES += \
- qfilesystemengine_win.cpp \
- qfilesystemiterator_win.cpp \
- qfsfileengine_win.cpp \
- qlocale_win.cpp \
- qoperatingsystemversion_win.cpp \
- qsettings_win.cpp \
- qsystemlibrary.cpp \
- generators/win32/registry.cpp
- HEADERS +=
- LIBS +=-LD:/Qt/Qt5.12.0/5.12.0/msvc2015_64/lib -lole32 -ladvapi32 -lkernel32 -lnetapi32 -lshell32
- mingw: LIBS += -luuid
- clang: QMAKE_CXXFLAGS += -fms-compatibility-version=19.00.23506 -Wno-microsoft-enum-value
- }
- /* Installation date */
- static const char qt_configure_installation [12+11] = "qt_instdate=2012-12-20";
-
- /* Installation Info */
- static const char qt_configure_prefix_path_str [12+256] = "qt_prfxpath=D:/Qt/Qt5.12.0";
- #ifdef QT_BUILD_QMAKE
- static const char qt_configure_ext_prefix_path_str [12+256] = "qt_epfxpath=D:/Qt/Qt5.12.0";
- static const char qt_configure_host_prefix_path_str [12+256] = "qt_hpfxpath=D:/Qt/Qt5.12.0";
- #endif
-
- static const short qt_configure_str_offsets[] = {
- 0, 38, 80, 118, 156, 194, 236, 278, 316, 350, 384, 431, 474,
- #ifdef QT_BUILD_QMAKE
- 514, 548, 554, 592, 630, 664, 665,
- #endif
- };
- static const char qt_configure_strs[] =
- "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/doc\0" "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/include\0" "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/lib\0" "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/lib\0" "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/bin\0" "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/plugins\0" "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/imports\0" "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/qml\0" "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64\0" "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64\0" "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/translations\0" "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/examples\0" "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/tests\0"
- #ifdef QT_BUILD_QMAKE
- "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64\0" "false\0" "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/bin\0" "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/lib\0" "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64\0" "\0" "win32-msvc\0"
- #endif
- ;
-
- #define QT_CONFIGURE_SETTINGS_PATH "/Library/Preferences/Qt"
-
- #ifdef QT_BUILD_QMAKE
- # define QT_CONFIGURE_SYSROOTIFY_PREFIX "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64"
- #endif
-
- #define QT_CONFIGURE_PREFIX_PATH qt_configure_prefix_path_str + 12
- #ifdef QT_BUILD_QMAKE
- # define QT_CONFIGURE_EXT_PREFIX_PATH qt_configure_ext_prefix_path_str + 12
- # define QT_CONFIGURE_HOST_PREFIX_PATH qt_configure_host_prefix_path_str + 12
- #endif
qconfig.cpp的生成是在configure过程中,该函数调用路径为: D:\Qt\Qt5.12.0\5.12.0\Src\qt.pro: load(qt_configure) D:\Qt\Qt5.12.0\5.12.0\Src\qtbase\mkspecs\features\qt_configure.prf: for (currentConfig, allConfigs) -> defineTest(qtConfProcessFeatures) -> defineTest(qtConfCheckFeature) -> defineTest(qtConfProcessOneOutput) D:\Qt\Qt5.12.0\5.12.0\Src\qtbase\configure.pri: defineTest(qtConfOutput_preparePaths) qtConfOutput_preparePaths中生成qconfig的代码如下:
- defineTest(qtConfOutput_preparePaths) {
- .....
- # populate qconfig.cpp (for qtcore)
-
- QT_CONFIGURE_STR_OFF = 0
- QT_CONFIGURE_STR_OFFSETS =
- QT_CONFIGURE_STRS =
-
- addConfStr($$config.rel_input.docdir)
- addConfStr($$config.rel_input.headerdir)
- addConfStr($$config.rel_input.libdir)
- addConfStr($$config.rel_input.libexecdir)
- addConfStr($$config.rel_input.bindir)
- addConfStr($$config.rel_input.plugindir)
- addConfStr($$config.rel_input.importdir)
- addConfStr($$config.rel_input.qmldir)
- addConfStr($$config.rel_input.archdatadir)
- addConfStr($$config.rel_input.datadir)
- addConfStr($$config.rel_input.translationdir)
- addConfStr($$config.rel_input.examplesdir)
- addConfStr($$config.rel_input.testsdir)
-
- QT_CONFIGURE_STR_OFFSETS_ALL = $$QT_CONFIGURE_STR_OFFSETS
- QT_CONFIGURE_STRS_ALL = $$QT_CONFIGURE_STRS
- QT_CONFIGURE_STR_OFFSETS =
- QT_CONFIGURE_STRS =
-
- addConfStr($$config.input.sysroot)
- addConfStr($$qmake_sysrootify)
- addConfStr($$config.rel_input.hostbindir)
- addConfStr($$config.rel_input.hostlibdir)
- addConfStr($$config.rel_input.hostdatadir)
- addConfStr($$XSPEC)
- addConfStr($$[QMAKE_SPEC])
-
- $${currentConfig}.output.qconfigSource = \
- "/* Installation date */" \
- "static const char qt_configure_installation [12+11] = \"qt_instdate=2012-12-20\";" \
- "" \
- "/* Installation Info */" \
- "static const char qt_configure_prefix_path_str [12+256] = \"qt_prfxpath=$$config.input.prefix\";" \
- "$${LITERAL_HASH}ifdef QT_BUILD_QMAKE" \
- "static const char qt_configure_ext_prefix_path_str [12+256] = \"qt_epfxpath=$$config.input.extprefix\";" \
- "static const char qt_configure_host_prefix_path_str [12+256] = \"qt_hpfxpath=$$config.input.hostprefix\";" \
- "$${LITERAL_HASH}endif" \
- "" \
- "static const short qt_configure_str_offsets[] = {" \
- $$QT_CONFIGURE_STR_OFFSETS_ALL \
- "$${LITERAL_HASH}ifdef QT_BUILD_QMAKE" \
- $$QT_CONFIGURE_STR_OFFSETS \
- "$${LITERAL_HASH}endif" \
- "};" \
- "static const char qt_configure_strs[] =" \
- $$QT_CONFIGURE_STRS_ALL \
- "$${LITERAL_HASH}ifdef QT_BUILD_QMAKE" \
- $$QT_CONFIGURE_STRS \
- "$${LITERAL_HASH}endif" \
- ";" \
- "" \
- "$${LITERAL_HASH}define QT_CONFIGURE_SETTINGS_PATH \"$$config.rel_input.sysconfdir\"" \
- "" \
- "$${LITERAL_HASH}ifdef QT_BUILD_QMAKE" \
- "$${LITERAL_HASH} define QT_CONFIGURE_SYSROOTIFY_PREFIX $$qmake_sysrootify" \
- "$${LITERAL_HASH}endif" \
- "" \
- "$${LITERAL_HASH}define QT_CONFIGURE_PREFIX_PATH qt_configure_prefix_path_str + 12" \
- "$${LITERAL_HASH}ifdef QT_BUILD_QMAKE" \
- "$${LITERAL_HASH} define QT_CONFIGURE_EXT_PREFIX_PATH qt_configure_ext_prefix_path_str + 12" \
- "$${LITERAL_HASH} define QT_CONFIGURE_HOST_PREFIX_PATH qt_configure_host_prefix_path_str + 12" \
- "$${LITERAL_HASH}endif"
- export($${currentConfig}.output.qconfigSource)
- ....
- }
我没有通过qt中的configure来生成qconfig.cpp,而是自己将其生成代码结合自己安装的qt的路径来生成qconfig.cpp。 将下面c++代码放到随便一个工程的main函数中,运行拿到这些路径。
- int main(int argc, char *argv[])
- {
- qDebug()<<"PrefixPath :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::PrefixPath);
- qDebug()<<"DocumentationPath :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::DocumentationPath);
- qDebug()<<"HeadersPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::HeadersPath);
- qDebug()<<"LibrariesPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::LibrariesPath);
- qDebug()<<"LibraryExecutablesPath:"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::LibraryExecutablesPath);
- qDebug()<<"BinariesPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::BinariesPath);
- qDebug()<<"PluginsPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::PluginsPath);
- qDebug()<<"ImportsPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::ImportsPath);
- qDebug()<<"Qml2ImportsPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::Qml2ImportsPath);
- qDebug()<<"ArchDataPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::ArchDataPath);
- qDebug()<<"DataPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::DataPath);
- qDebug()<<"TranslationsPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::TranslationsPath);
- qDebug()<<"ExamplesPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::ExamplesPath);
- qDebug()<<"TestsPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::TestsPath);
- }
下面是qt_configure.prf中用qmake language写的生成qconfig.cpp的代码,将其复制到随便一个工程的.pro中,注意下面的那一堆路径与上面生成的路径对应代入一下,然后执行qmake,然后将message输出的内容复制到qconfig中对应的地方。(我电脑qt安装路径为D:/Qt,src路径为D:\Qt\Qt5.12.0\5.12.0)
- QT_CONFIGURE_STR_OFF = 0
- QT_CONFIGURE_STR_OFFSETS =
- QT_CONFIGURE_STRS =
-
- defineTest(addConfStr) {
- QT_CONFIGURE_STR_OFFSETS += " $$QT_CONFIGURE_STR_OFF,"
- QT_CONFIGURE_STRS += " \"$$1\\0\""
- QT_CONFIGURE_STR_OFF = $$num_add($$QT_CONFIGURE_STR_OFF, $$str_size($$1), 1)
- export(QT_CONFIGURE_STR_OFFSETS)
- export(QT_CONFIGURE_STRS)
- export(QT_CONFIGURE_STR_OFF)
- }
-
- config.rel_input.docdir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/doc"
- config.rel_input.headerdir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/include"
- config.rel_input.libdir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/lib"
- config.rel_input.libexecdir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/lib"
- config.rel_input.bindir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/bin"
- config.rel_input.plugindir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/plugins"
- config.rel_input.importdir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/imports"
- config.rel_input.qmldir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/qml"
- config.rel_input.archdatadir= "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64"
- config.rel_input.datadir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64"
- config.rel_input.translationdir="D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/translations"
- config.rel_input.examplesdir= "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/examples"
- config.rel_input.testsdir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/tests"
- config.input.sysroot = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64"
- qmake_sysrootify = false
- config.rel_input.hostbindir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/bin"
- config.rel_input.hostlibdir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/lib"
- config.rel_input.hostdatadir= "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64"
- #XSPEC =win32
-
- addConfStr($$config.rel_input.docdir)
- addConfStr($$config.rel_input.headerdir)
- addConfStr($$config.rel_input.libdir)
- addConfStr($$config.rel_input.libexecdir)
- addConfStr($$config.rel_input.bindir)
- addConfStr($$config.rel_input.plugindir)
- addConfStr($$config.rel_input.importdir)
- addConfStr($$config.rel_input.qmldir)
- addConfStr($$config.rel_input.archdatadir)
- addConfStr($$config.rel_input.datadir)
- addConfStr($$config.rel_input.translationdir)
- addConfStr($$config.rel_input.examplesdir)
- addConfStr($$config.rel_input.testsdir)
-
- QT_CONFIGURE_STR_OFFSETS_ALL = $$QT_CONFIGURE_STR_OFFSETS
- QT_CONFIGURE_STRS_ALL = $$QT_CONFIGURE_STRS
- QT_CONFIGURE_STR_OFFSETS =
- QT_CONFIGURE_STRS =
-
- addConfStr($$config.input.sysroot)
- addConfStr($$qmake_sysrootify)
- addConfStr($$config.rel_input.hostbindir)
- addConfStr($$config.rel_input.hostlibdir)
- addConfStr($$config.rel_input.hostdatadir)
- addConfStr($$XSPEC)
- addConfStr($$[QMAKE_SPEC])
-
- message(start)
- !build_pass:message($$QT_CONFIGURE_STR_OFFSETS_ALL)
- !build_pass:message($$QT_CONFIGURE_STR_OFFSETS)
- !build_pass:message($$QT_CONFIGURE_STRS_ALL)
- !build_pass:message($$QT_CONFIGURE_STRS)
至此,就能正常编译qmake工程了。
配置参数:
-d表示日志等级,一个-d表示日志等级为1,两个-d表示日志等级为2。 一定记得通过-o将输出指定到其他路径,否则默认生成到当前路径,调试时产生的Makefile会覆盖掉qmake工程的Makefile!
E:/test/t.pro -o E:/test/ -spec win32-msvc "CONFIG+=debug" "CONFIG+=qml_debug" -d -d
- #E:\test\t.pro
- $$escape_expand(\n)
- var=10
- tt=0
- for(tt,forever):{
- var=$$num_add($$var,-1)
- message(here$$var)
- equals(var,9):{
- break()
- }
- }
用qt打开qmake工程。
1、原始工程拷贝过来后执行qmake,出现有一些*.cpp找不到的提示,这些文件不是在qmake工程的目录下,而是在qtbase中其他路径下,qmake.pro中的VPATH变量,表示指示qmake.exe当前路径中找不到*.cpp时,从VPATH指示的路径中寻找。INCLUDEPATH表示当前目录下没找到的头文件从INCLUDEPATH中寻找。
所以对VPATH和INCLUDEPATH做一个小小做个修改(shadowed(..)的作用是取到源码的qmake上一级的路径,也就是D:\Qt\Qt5.12.0\5.12.0\Src\qtbase)
2、 然后是register.cpp找不到,他其实就在qmake\generators\win32中,最如下修改解决:![]()
3、然后构建,发现这么一堆问题:
每行的错误表示编译后面名字的obj文件的时候对应的函数找不到。于是将对应函数所在文件加入到qmake的工程中。于是在SOURECE和HEADERS中分别加入这些源文件和头文件:

4、然后是找不到系统库函数:
系统库函数是系统库中,用cn.bing.com搜索msdn CommandLineToArgvW,能找到该函数在Shell32.lib中,将该lib加入qmake.pro的LIBS中。另外需要注意的是,系统库path和头文件path是在qt的环境变量LIBS和INCLUDE中设置的,这两个宏是cl.exe默认使用的。具体可以查看这里:
qt main.obj:-1: error: LNK2019: 无法解析的外部符号 __imp_CommandLineToArgvW,该符号在函数 “int __cdecl dumpMacros(wc_丘上人的博客-CSDN博客
修改LIBS
至此,qmake就编译完成了。过程中编译失败,可能是因为没有先清除 再构建导致。
5、中间胡乱操作时,过程中碰到了下面错误:![]()
D:\Qt\Qt5.12.0\5.12.0\Src\qtbase\src\corelib\tools\qarraydata.cpp:52: error: C2491: “QArrayData::shared_null”: 不允许 dllimport 静态数据成员 的定义
这是因为定义的宏开关:QT_BOOTSTRAPPED与core lib 冲突
下载qt源码方法:qt creator debug无法调试 进入 qt源码_丘上人的博客-CSDN博客_qt不能debug
qmake运行时依赖的配置文件集 qmake.conf、.qmake.conf、.qmake.stash、.qmake.super、.qmake.cache文件_丘上人的博客-CSDN博客