当前位置: 首页 > news >正文

用qt编译qmake

使用qt版本。

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

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的源码与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

# 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
}

 qconfig.cpp

/* 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工程了。

编译过程及其中遇到问题:
用qt打开qmake工程。
原始工程拷贝过来后执行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)

 然后是register.cpp找不到,他其实就在qmake\generators\win32中,最如下修改解决:

然后构建,发现这么一堆问题:

每行的错误表示编译后面名字的obj文件的时候对应的函数找不到。于是将对应函数所在文件加入到qmake的工程中。于是在SOURECE和HEADERS中分别加入这些源文件和头文件:

 然后是找不到系统库函数:

系统库函数是系统库中,用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就编译完成了。过程中编译失败,可能是因为没有先清除 再构建导致。

中间胡乱操作时,过程中碰到了下面错误:
​​​​​​​
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路径配置

相关文章:

  • 后端 学习 前端 Vue 框架基础知识
  • 机器学习论文-实验部分常用代码大总结
  • 数据结构:AVL树——C++实现(待补充)
  • Opencv之频率域滤波
  • 海思3559万能平台搭建:OSD功能的优化
  • 从1到100这100个自然数中任取10个数,使他们的倒数和等于1。这10个数分别是多少?
  • 【香橙派4B】6、测试串口
  • 【408】【数据结构】【图】
  • 【架构设计】如何实现3ms内从1000w级别的用户里面随机抽奖出100名用户
  • HTB-Chatterbox
  • 矩阵乘法的消去律
  • FL Studio最新20.9版本完整FL水果中文语言更新
  • JAVA集合(二)List接口详解
  • 矩阵的秩的性质
  • Redis在SpringBoot项目中使用
  • [分享]iOS开发 - 实现UITableView Plain SectionView和table不停留一起滑动
  • [译] React v16.8: 含有Hooks的版本
  • ABAP的include关键字,Java的import, C的include和C4C ABSL 的import比较
  • angular2 简述
  • css选择器
  • django开发-定时任务的使用
  • ES6系统学习----从Apollo Client看解构赋值
  • JavaScript对象详解
  • LintCode 31. partitionArray 数组划分
  • Linux gpio口使用方法
  • Linux学习笔记6-使用fdisk进行磁盘管理
  • Lucene解析 - 基本概念
  • miniui datagrid 的客户端分页解决方案 - CS结合
  • spring学习第二天
  • SQL 难点解决:记录的引用
  • vue2.0开发聊天程序(四) 完整体验一次Vue开发(下)
  • 阿里研究院入选中国企业智库系统影响力榜
  • 不发不行!Netty集成文字图片聊天室外加TCP/IP软硬件通信
  • 不上全站https的网站你们就等着被恶心死吧
  • 大快搜索数据爬虫技术实例安装教学篇
  • 免费小说阅读小程序
  • 七牛云假注销小指南
  • 删除表内多余的重复数据
  • 网页视频流m3u8/ts视频下载
  • d²y/dx²; 偏导数问题 请问f1 f2是什么意思
  • ![CDATA[ ]] 是什么东东
  • (14)Hive调优——合并小文件
  • (2.2w字)前端单元测试之Jest详解篇
  • (Demo分享)利用原生JavaScript-随机数-实现做一个烟花案例
  • (Java数据结构)ArrayList
  • (搬运以学习)flask 上下文的实现
  • (二)windows配置JDK环境
  • (六)库存超卖案例实战——使用mysql分布式锁解决“超卖”问题
  • (强烈推荐)移动端音视频从零到上手(上)
  • (十一)c52学习之旅-动态数码管
  • (五)网络优化与超参数选择--九五小庞
  • (转)GCC在C语言中内嵌汇编 asm __volatile__
  • (转)Oracle 9i 数据库设计指引全集(1)
  • (转)创业家杂志:UCWEB天使第一步
  • (转)从零实现3D图像引擎:(8)参数化直线与3D平面函数库