• 用qt编译qmake


    使用qt版本windows qt5.12.0。

    目的:为了调试qmake代码,深入理解qmake代码逻辑,了解qmake实现细节,以及了解qt文档中未提及或提及但不清楚的关于qmake language的CONFIG参数、变量、内置变量、代码逻辑 和 内置函数。

    有关qmake language的词法、语法、内置函数qmake language_丘上人的博客-CSDN博客

    qmake的意义

    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编译过程

    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文件:

    qmake.pro

    1. # This project is not actually used to build qmake, but to support development
    2. # with Qt Creator. The real build system is made up by the Makefile templates
    3. # and the configures.
    4. option(host_build)
    5. CONFIG += console
    6. CONFIG -= qt app_bundle
    7. DEFINES += \
    8. PROEVALUATOR_FULL \
    9. QT_BOOTSTRAPPED \
    10. QT_BUILD_QMAKE \
    11. QT_NO_FOREACH \
    12. $$shell_quote(QT_VERSION_STR=\"$$QT_VERSION\") \
    13. QT_VERSION_MAJOR=$$QT_MAJOR_VERSION \
    14. QT_VERSION_MINOR=$$QT_MINOR_VERSION \
    15. QT_VERSION_PATCH=$$QT_PATCH_VERSION
    16. win32: DEFINES += \
    17. UNICODE \
    18. _ENABLE_EXTENDED_ALIGNED_STORAGE \
    19. _CRT_SECURE_NO_WARNINGS _SCL_SECURE_NO_WARNINGS
    20. # qmake code
    21. PRECOMPILED_HEADER += qmake_pch.h
    22. INCLUDEPATH += \
    23. . \
    24. library \
    25. generators \
    26. generators/unix \
    27. generators/win32 \
    28. generators/mac
    29. SOURCES += \
    30. main.cpp \
    31. meta.cpp \
    32. option.cpp \
    33. project.cpp \
    34. property.cpp \
    35. library/ioutils.cpp \
    36. library/proitems.cpp \
    37. library/qmakebuiltins.cpp \
    38. library/qmakeevaluator.cpp \
    39. library/qmakeglobals.cpp \
    40. library/qmakeparser.cpp \
    41. library/qmakevfs.cpp \
    42. generators/makefile.cpp \
    43. generators/makefiledeps.cpp \
    44. generators/metamakefile.cpp \
    45. generators/projectgenerator.cpp \
    46. generators/xmloutput.cpp \
    47. generators/mac/pbuilder_pbx.cpp \
    48. generators/unix/unixmake.cpp \
    49. generators/unix/unixmake2.cpp \
    50. generators/win32/mingw_make.cpp \
    51. generators/win32/msbuild_objectmodel.cpp \
    52. generators/win32/msvc_nmake.cpp \
    53. generators/win32/msvc_objectmodel.cpp \
    54. generators/win32/msvc_vcproj.cpp \
    55. generators/win32/msvc_vcxproj.cpp \
    56. generators/win32/winmakefile.cpp
    57. HEADERS += \
    58. cachekeys.h \
    59. meta.h \
    60. option.h \
    61. project.h \
    62. property.h \
    63. library/ioutils.h \
    64. library/proitems.h \
    65. library/qmake_global.h \
    66. library/qmakeevaluator.h \
    67. library/qmakeevaluator_p.h \
    68. library/qmakeglobals.h \
    69. library/qmakeparser.h \
    70. library/qmakevfs.h \
    71. generators/makefile.h \
    72. generators/makefiledeps.h \
    73. generators/metamakefile.h \
    74. generators/projectgenerator.h \
    75. generators/xmloutput.h \
    76. generators/mac/pbuilder_pbx.h \
    77. generators/unix/unixmake.h \
    78. generators/win32/mingw_make.h \
    79. generators/win32/msbuild_objectmodel.h \
    80. generators/win32/msvc_nmake.h \
    81. generators/win32/msvc_objectmodel.h \
    82. generators/win32/msvc_vcproj.h \
    83. generators/win32/msvc_vcxproj.h \
    84. generators/win32/winmakefile.h
    85. # qt code
    86. bp = D:/Qt/Qt5.12.0/5.12.0/Src/qtbase #$$shadowed(..)
    87. INCLUDEPATH += \
    88. $$bp/include $$bp/include/QtCore \
    89. $$bp/include/QtCore/$$QT_VERSION $$bp/include/QtCore/$$QT_VERSION/QtCore \
    90. $$bp/src/corelib/global
    91. VPATH += \
    92. $$bp/src/corelib/global \
    93. $$bp/src/corelib/tools \
    94. $$bp/src/corelib/kernel \
    95. $$bp/src/corelib/codecs \
    96. $$bp/src/corelib/plugin \
    97. $$bp/src/corelib/io \
    98. $$bp/src/corelib/serialization
    99. SOURCES += \
    100. qabstractfileengine.cpp \
    101. qarraydata.cpp \
    102. qbitarray.cpp \
    103. qbuffer.cpp \
    104. qbytearray.cpp \
    105. qbytearraymatcher.cpp \
    106. qcryptographichash.cpp \
    107. qdatetime.cpp \
    108. qdir.cpp \
    109. qdiriterator.cpp \
    110. qfile.cpp \
    111. qfiledevice.cpp \
    112. qfileinfo.cpp \
    113. qfilesystemengine.cpp \
    114. qfilesystementry.cpp \
    115. qfsfileengine.cpp \
    116. qfsfileengine_iterator.cpp \
    117. qglobal.cpp \
    118. qhash.cpp \
    119. qiodevice.cpp \
    120. qjson.cpp \
    121. qjsonarray.cpp \
    122. qjsondocument.cpp \
    123. qjsonobject.cpp \
    124. qjsonparser.cpp \
    125. qjsonvalue.cpp \
    126. qlibraryinfo.cpp \
    127. qlinkedlist.cpp \
    128. qlist.cpp \
    129. qlocale.cpp \
    130. qlocale_tools.cpp \
    131. qlogging.cpp \
    132. qmalloc.cpp \
    133. qmap.cpp \
    134. qmetatype.cpp \
    135. qnumeric.cpp \
    136. qregexp.cpp \
    137. qsettings.cpp \
    138. qstring.cpp \
    139. qstring_compat.cpp \
    140. qstringlist.cpp \
    141. qsystemerror.cpp \
    142. qtemporaryfile.cpp \
    143. qtextcodec.cpp \
    144. qtextstream.cpp \
    145. qutfcodec.cpp \
    146. quuid.cpp \
    147. qvariant.cpp \
    148. qversionnumber.cpp \
    149. qvsnprintf.cpp \
    150. qxmlstream.cpp \
    151. qxmlutils.cpp \
    152. qdebug.cpp \
    153. qringbuffer.cpp \
    154. qoperatingsystemversion.cpp \
    155. qrandom.cpp \
    156. qendian.cpp
    157. HEADERS += \
    158. qabstractfileengine_p.h \
    159. qarraydata.h \
    160. qarraydataops.h \
    161. qarraydatapointer.h \
    162. qbitarray.h \
    163. qbuffer.h \
    164. qbytearray.h \
    165. qbytearraymatcher.h \
    166. qchar.h \
    167. qcryptographichash.h \
    168. qdatetime.h \
    169. qdatetime_p.h \
    170. qdir.h \
    171. qdir_p.h \
    172. qdiriterator.h \
    173. qfile.h \
    174. qfileinfo.h \
    175. qglobal.h \
    176. qhash.h \
    177. qiodevice.h \
    178. qjson.h \
    179. qjsonarray.h \
    180. qjsondocument.h \
    181. qjsonobject.h \
    182. qjsonparser.h \
    183. qjsonvalue.h \
    184. qjsonwriter.h \
    185. qlinkedlist.h \
    186. qlist.h \
    187. qlocale.h \
    188. qlocale_tools_p.h \
    189. qmalloc.h \
    190. qmap.h \
    191. qmetatype.h \
    192. qnumeric.h \
    193. qregexp.h \
    194. qstring.h \
    195. qstringlist.h \
    196. qstringmatcher.h \
    197. qsystemerror_p.h \
    198. qtemporaryfile.h \
    199. qtextcodec.h \
    200. qtextstream.h \
    201. qutfcodec.h \
    202. quuid.h \
    203. qvector.h \
    204. qversionnumber.h \
    205. qxmlstream.h \
    206. qxmlutils.h \
    207. qdebug_p.h \
    208. qiodevice_p.h \
    209. qringbuffer_p.h \
    210. qoperatingsystemversion.h \
    211. qrandom.h \
    212. qendian.h
    213. unix {
    214. SOURCES += \
    215. qcore_unix.cpp \
    216. qfilesystemengine_unix.cpp \
    217. qfilesystemiterator_unix.cpp \
    218. qfsfileengine_unix.cpp \
    219. qlocale_unix.cpp
    220. macos {
    221. SOURCES += \
    222. qcore_foundation.mm \
    223. qcore_mac.cpp \
    224. qoperatingsystemversion_darwin.mm \
    225. qsettings_mac.cpp
    226. LIBS += \
    227. -framework ApplicationServices \
    228. -framework CoreServices \
    229. -framework Foundation
    230. QMAKE_CXXFLAGS += -fconstant-cfstrings
    231. }
    232. } else {
    233. SOURCES += \
    234. qfilesystemengine_win.cpp \
    235. qfilesystemiterator_win.cpp \
    236. qfsfileengine_win.cpp \
    237. qlocale_win.cpp \
    238. qoperatingsystemversion_win.cpp \
    239. qsettings_win.cpp \
    240. qsystemlibrary.cpp \
    241. generators/win32/registry.cpp
    242. HEADERS +=
    243. LIBS +=-LD:/Qt/Qt5.12.0/5.12.0/msvc2015_64/lib -lole32 -ladvapi32 -lkernel32 -lnetapi32 -lshell32
    244. mingw: LIBS += -luuid
    245. clang: QMAKE_CXXFLAGS += -fms-compatibility-version=19.00.23506 -Wno-microsoft-enum-value
    246. }

     qconfig.cpp

    1. /* Installation date */
    2. static const char qt_configure_installation [12+11] = "qt_instdate=2012-12-20";
    3. /* Installation Info */
    4. static const char qt_configure_prefix_path_str [12+256] = "qt_prfxpath=D:/Qt/Qt5.12.0";
    5. #ifdef QT_BUILD_QMAKE
    6. static const char qt_configure_ext_prefix_path_str [12+256] = "qt_epfxpath=D:/Qt/Qt5.12.0";
    7. static const char qt_configure_host_prefix_path_str [12+256] = "qt_hpfxpath=D:/Qt/Qt5.12.0";
    8. #endif
    9. static const short qt_configure_str_offsets[] = {
    10. 0, 38, 80, 118, 156, 194, 236, 278, 316, 350, 384, 431, 474,
    11. #ifdef QT_BUILD_QMAKE
    12. 514, 548, 554, 592, 630, 664, 665,
    13. #endif
    14. };
    15. static const char qt_configure_strs[] =
    16. "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"
    17. #ifdef QT_BUILD_QMAKE
    18. "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"
    19. #endif
    20. ;
    21. #define QT_CONFIGURE_SETTINGS_PATH "/Library/Preferences/Qt"
    22. #ifdef QT_BUILD_QMAKE
    23. # define QT_CONFIGURE_SYSROOTIFY_PREFIX "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64"
    24. #endif
    25. #define QT_CONFIGURE_PREFIX_PATH qt_configure_prefix_path_str + 12
    26. #ifdef QT_BUILD_QMAKE
    27. # define QT_CONFIGURE_EXT_PREFIX_PATH qt_configure_ext_prefix_path_str + 12
    28. # define QT_CONFIGURE_HOST_PREFIX_PATH qt_configure_host_prefix_path_str + 12
    29. #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的代码如下:
    
    1. defineTest(qtConfOutput_preparePaths) {
    2. .....
    3. # populate qconfig.cpp (for qtcore)
    4. QT_CONFIGURE_STR_OFF = 0
    5. QT_CONFIGURE_STR_OFFSETS =
    6. QT_CONFIGURE_STRS =
    7. addConfStr($$config.rel_input.docdir)
    8. addConfStr($$config.rel_input.headerdir)
    9. addConfStr($$config.rel_input.libdir)
    10. addConfStr($$config.rel_input.libexecdir)
    11. addConfStr($$config.rel_input.bindir)
    12. addConfStr($$config.rel_input.plugindir)
    13. addConfStr($$config.rel_input.importdir)
    14. addConfStr($$config.rel_input.qmldir)
    15. addConfStr($$config.rel_input.archdatadir)
    16. addConfStr($$config.rel_input.datadir)
    17. addConfStr($$config.rel_input.translationdir)
    18. addConfStr($$config.rel_input.examplesdir)
    19. addConfStr($$config.rel_input.testsdir)
    20. QT_CONFIGURE_STR_OFFSETS_ALL = $$QT_CONFIGURE_STR_OFFSETS
    21. QT_CONFIGURE_STRS_ALL = $$QT_CONFIGURE_STRS
    22. QT_CONFIGURE_STR_OFFSETS =
    23. QT_CONFIGURE_STRS =
    24. addConfStr($$config.input.sysroot)
    25. addConfStr($$qmake_sysrootify)
    26. addConfStr($$config.rel_input.hostbindir)
    27. addConfStr($$config.rel_input.hostlibdir)
    28. addConfStr($$config.rel_input.hostdatadir)
    29. addConfStr($$XSPEC)
    30. addConfStr($$[QMAKE_SPEC])
    31. $${currentConfig}.output.qconfigSource = \
    32. "/* Installation date */" \
    33. "static const char qt_configure_installation [12+11] = \"qt_instdate=2012-12-20\";" \
    34. "" \
    35. "/* Installation Info */" \
    36. "static const char qt_configure_prefix_path_str [12+256] = \"qt_prfxpath=$$config.input.prefix\";" \
    37. "$${LITERAL_HASH}ifdef QT_BUILD_QMAKE" \
    38. "static const char qt_configure_ext_prefix_path_str [12+256] = \"qt_epfxpath=$$config.input.extprefix\";" \
    39. "static const char qt_configure_host_prefix_path_str [12+256] = \"qt_hpfxpath=$$config.input.hostprefix\";" \
    40. "$${LITERAL_HASH}endif" \
    41. "" \
    42. "static const short qt_configure_str_offsets[] = {" \
    43. $$QT_CONFIGURE_STR_OFFSETS_ALL \
    44. "$${LITERAL_HASH}ifdef QT_BUILD_QMAKE" \
    45. $$QT_CONFIGURE_STR_OFFSETS \
    46. "$${LITERAL_HASH}endif" \
    47. "};" \
    48. "static const char qt_configure_strs[] =" \
    49. $$QT_CONFIGURE_STRS_ALL \
    50. "$${LITERAL_HASH}ifdef QT_BUILD_QMAKE" \
    51. $$QT_CONFIGURE_STRS \
    52. "$${LITERAL_HASH}endif" \
    53. ";" \
    54. "" \
    55. "$${LITERAL_HASH}define QT_CONFIGURE_SETTINGS_PATH \"$$config.rel_input.sysconfdir\"" \
    56. "" \
    57. "$${LITERAL_HASH}ifdef QT_BUILD_QMAKE" \
    58. "$${LITERAL_HASH} define QT_CONFIGURE_SYSROOTIFY_PREFIX $$qmake_sysrootify" \
    59. "$${LITERAL_HASH}endif" \
    60. "" \
    61. "$${LITERAL_HASH}define QT_CONFIGURE_PREFIX_PATH qt_configure_prefix_path_str + 12" \
    62. "$${LITERAL_HASH}ifdef QT_BUILD_QMAKE" \
    63. "$${LITERAL_HASH} define QT_CONFIGURE_EXT_PREFIX_PATH qt_configure_ext_prefix_path_str + 12" \
    64. "$${LITERAL_HASH} define QT_CONFIGURE_HOST_PREFIX_PATH qt_configure_host_prefix_path_str + 12" \
    65. "$${LITERAL_HASH}endif"
    66. export($${currentConfig}.output.qconfigSource)
    67. ....
    68. }
    我没有通过qt中的configure来生成qconfig.cpp,而是自己将其生成代码结合自己安装的qt的路径来生成qconfig.cpp。
    将下面c++代码放到随便一个工程的main函数中,运行拿到这些路径。
    
    1. int main(int argc, char *argv[])
    2. {
    3. qDebug()<<"PrefixPath :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::PrefixPath);
    4. qDebug()<<"DocumentationPath :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::DocumentationPath);
    5. qDebug()<<"HeadersPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::HeadersPath);
    6. qDebug()<<"LibrariesPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::LibrariesPath);
    7. qDebug()<<"LibraryExecutablesPath:"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::LibraryExecutablesPath);
    8. qDebug()<<"BinariesPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::BinariesPath);
    9. qDebug()<<"PluginsPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::PluginsPath);
    10. qDebug()<<"ImportsPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::ImportsPath);
    11. qDebug()<<"Qml2ImportsPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::Qml2ImportsPath);
    12. qDebug()<<"ArchDataPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::ArchDataPath);
    13. qDebug()<<"DataPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::DataPath);
    14. qDebug()<<"TranslationsPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::TranslationsPath);
    15. qDebug()<<"ExamplesPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::ExamplesPath);
    16. qDebug()<<"TestsPath, :"<<QLibraryInfo::location(QLibraryInfo::LibraryLocation::TestsPath);
    17. }
    下面是qt_configure.prf中用qmake language写的生成qconfig.cpp的代码,将其复制到随便一个工程的.pro中,注意下面的那一堆路径与上面生成的路径对应代入一下,然后执行qmake,然后将message输出的内容复制到qconfig中对应的地方。(我电脑qt安装路径为D:/Qt,src路径为D:\Qt\Qt5.12.0\5.12.0)
    
    1. QT_CONFIGURE_STR_OFF = 0
    2. QT_CONFIGURE_STR_OFFSETS =
    3. QT_CONFIGURE_STRS =
    4. defineTest(addConfStr) {
    5. QT_CONFIGURE_STR_OFFSETS += " $$QT_CONFIGURE_STR_OFF,"
    6. QT_CONFIGURE_STRS += " \"$$1\\0\""
    7. QT_CONFIGURE_STR_OFF = $$num_add($$QT_CONFIGURE_STR_OFF, $$str_size($$1), 1)
    8. export(QT_CONFIGURE_STR_OFFSETS)
    9. export(QT_CONFIGURE_STRS)
    10. export(QT_CONFIGURE_STR_OFF)
    11. }
    12. config.rel_input.docdir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/doc"
    13. config.rel_input.headerdir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/include"
    14. config.rel_input.libdir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/lib"
    15. config.rel_input.libexecdir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/lib"
    16. config.rel_input.bindir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/bin"
    17. config.rel_input.plugindir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/plugins"
    18. config.rel_input.importdir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/imports"
    19. config.rel_input.qmldir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/qml"
    20. config.rel_input.archdatadir= "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64"
    21. config.rel_input.datadir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64"
    22. config.rel_input.translationdir="D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/translations"
    23. config.rel_input.examplesdir= "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/examples"
    24. config.rel_input.testsdir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/tests"
    25. config.input.sysroot = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64"
    26. qmake_sysrootify = false
    27. config.rel_input.hostbindir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/bin"
    28. config.rel_input.hostlibdir = "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64/lib"
    29. config.rel_input.hostdatadir= "D:/Qt/Qt5.12.0/5.12.0/msvc2015_64"
    30. #XSPEC =win32
    31. addConfStr($$config.rel_input.docdir)
    32. addConfStr($$config.rel_input.headerdir)
    33. addConfStr($$config.rel_input.libdir)
    34. addConfStr($$config.rel_input.libexecdir)
    35. addConfStr($$config.rel_input.bindir)
    36. addConfStr($$config.rel_input.plugindir)
    37. addConfStr($$config.rel_input.importdir)
    38. addConfStr($$config.rel_input.qmldir)
    39. addConfStr($$config.rel_input.archdatadir)
    40. addConfStr($$config.rel_input.datadir)
    41. addConfStr($$config.rel_input.translationdir)
    42. addConfStr($$config.rel_input.examplesdir)
    43. addConfStr($$config.rel_input.testsdir)
    44. QT_CONFIGURE_STR_OFFSETS_ALL = $$QT_CONFIGURE_STR_OFFSETS
    45. QT_CONFIGURE_STRS_ALL = $$QT_CONFIGURE_STRS
    46. QT_CONFIGURE_STR_OFFSETS =
    47. QT_CONFIGURE_STRS =
    48. addConfStr($$config.input.sysroot)
    49. addConfStr($$qmake_sysrootify)
    50. addConfStr($$config.rel_input.hostbindir)
    51. addConfStr($$config.rel_input.hostlibdir)
    52. addConfStr($$config.rel_input.hostdatadir)
    53. addConfStr($$XSPEC)
    54. addConfStr($$[QMAKE_SPEC])
    55. message(start)
    56. !build_pass:message($$QT_CONFIGURE_STR_OFFSETS_ALL)
    57. !build_pass:message($$QT_CONFIGURE_STR_OFFSETS)
    58. !build_pass:message($$QT_CONFIGURE_STRS_ALL)
    59. !build_pass:message($$QT_CONFIGURE_STRS)

    至此,就能正常编译qmake工程了。

    调试运行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
    1. #E:\test\t.pro
    2. $$escape_expand(\n)
    3. var=10
    4. tt=0
    5. for(tt,forever):{
    6. var=$$num_add($$var,-1)
    7. message(here$$var)
    8. equals(var,9):{
    9. break()
    10. }
    11. }

    编译过程及其中遇到过的问题

    用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博客

    qt 工程构建过程 默认构建路径设置 通过Dos窗口运行命令编译qt工程_丘上人的博客-CSDN博客_qt路径配置

  • 相关阅读:
    openGauss3.1.0 版本的gs_stack功能解密
    自然语言处理(NLP)是什么?
    国内外9大最佳测试管理平台
    c# 类的介绍及延伸
    .NET桌面程序集成Web网页开发的十种解决方案
    Linux进程概念
    微信小程序-读取数据
    Django路由层解析
    【Kaggle】如何有效避免OOM(out of memory)和漫长的炼丹过程
    新消费时代,零售业的进与退?
  • 原文地址:https://blog.csdn.net/qiushangren/article/details/127132779