The latest version of QT6 2.2 compilation

Posted by nevvermind on Thu, 16 Dec 2021 15:56:17 +0100

Qt 6.2.2 compilation

Compiling the source code of large-scale projects, if you haven't done it, you must find it somewhat difficult, but once you practice it, you will have a general idea in your mind. So don't have resistance and practice.

From my practical experience, the core is one point: the configuration of the environment. How to achieve the optimal configuration of the environment and not pollute other environments is the core. We should also pay attention to the output of configuration information.

For a large project, there is basically no problem with the code. If there are some very low-level compilation errors in the compilation process, I think there is a great possibility that there is a problem with the environment configuration.

For example, I have problems during compilation:

  D:/qt/qt-everywhere-src-6.2.2/qtbase/src/corelib/text/qstringconverter.h:188:87: internal compiler error: in make_rtl_for_nonlocal_decl, at cp/decl.c:6590
     Q_CORE_EXPORT static const Interface encodingInterfaces[Encoding::LastEncoding + 1];

It took me a long time to check the above error. The conclusion is that gcc version 8.3 does not support this writing method. Just upgrade the gcc version.

So how do I upgrade gcc for windows? I went to google and didn't find a solution.

Later, there was no way. I manually modified the source code. I forgot how to modify it now. In short, the compilation has passed, and I am still complacent about it.

Later, I made a mistake and was really helpless

tst_graphicshelpergl3_2.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Qt3DRender::Render::OpenGL::ShaderUniform::ShaderUniform(void)" (__imp_??0ShaderUniform@OpenGL@Render@Qt3DRender@@QAE@XZ) referenced in function "private: void __thiscall tst_GraphicsHelperGL3_2::uniformsByteSize(void)" (?uniformsByteSize@tst_GraphicsHelperGL3_2@@AAEXXZ)
tst_graphicshelpergl3_2.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Qt3DRender::Render::OpenGL::ShaderUniform::~ShaderUniform(void)" (__imp_??1ShaderUniform@OpenGL@Render@Qt3DRender@@QAE@XZ) referenced in function "struct Qt3DRender::Render::OpenGL::ShaderUniform * __cdecl std::_Insertion_sort_unchecked<struct Qt3DRender::Render::OpenGL::ShaderUniform *,class <lambda_041645316411b6d2c2b7c2cbb27dc4bf> >(struct Qt3DRender::Render::OpenGL::ShaderUniform * const,struct Qt3DRender::Render::OpenGL::ShaderUniform * const,class <lambda_041645316411b6d2c2b7c2cbb27dc4bf>)" (??$_Insertion_sort_unchecked@PAUShaderUniform@OpenGL@Render@Qt3DRender@@V<lambda_041645316411b6d2c2b7c2cbb27dc4bf>@@@std@@YAPAUShaderUniform@OpenGL@Render@Qt3DRender@@QAU1234@0V<lambda_041645316411b6d2c2b7c2cbb27dc4bf>@@@Z)
tst_graphicshelpergl3_2.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Qt3DRender::Render::OpenGL::ShaderUniform::ShaderUniform(struct Qt3DRender::Render::OpenGL::ShaderUniform const &)" (__imp_??0ShaderUniform@OpenGL@Render@Qt3DRender@@QAE@ABU0123@@Z) referenced in function "private: void __thiscall tst_GraphicsHelperGL3_2::programUniformsAndLocations(void)" (?programUniformsAndLocations@tst_GraphicsHelperGL3_2@@AAEXXZ)

All kinds of link errors, which I really have a big head.

I began to reflect... It may not be the code, but my problem. I re executed configure Bat, see a very important message. I actually saw that make specified gcc as the compiler.

I wonder why I still use gcc instead of initializing the environment of vs2019 compiler. It's really a day's dog. Only here did I realize that there was something wrong with my environment, but it has been two days since I just started compiling Qt source code.

I started to check the environmental problems, and finally found that the problem was with me. When I specified the perl directory, I specified an additional bin directory, which contains GCC exe.

So: the compilation environment is very important

1. Tool preparation

Note: don't compile QDoc first, because according to the official documents, the Clang compiler is used to compile QDoc.

  • Qt 6.2.2 source address

  • cmake tool

  • perl tools

  • ninja

  • vs2019 Enterprise

The above tools need to be downloaded from foreign websites. In order to facilitate everyone, I downloaded them directly and put them on Baidu online disk.

Link: Extraction code: s3r7

Qt source address, we can directly Tsinghua source on it.

2. Environmental collocation

REM Find you vs2019 Initialization environment bat Catalog, I use it enterprise Version, the unused version only needs to replace the following"Enterprise"That's it
CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x86

SET _ROOT=D:\qt\qt-6.2.2
SET PATH=D:\soft_dev\build_qt_devs\cmake-3.22.0\bin;%PATH%
SET PATH=%_ROOT%\qtbase\bin;%PATH%
SET PATH=D:\soft_dev\build_qt_devs\strawberry-perl-\perl\bin;%PATH%
SET PATH=D:\soft_dev\build_qt_devs\ninja-win;%PATH%

set "MY_INSTALL_PATH=D:\qt\qt-6.2.2\bin"
configure.bat -prefix %MY_INSTALL_PATH% -DQT_NO_EXCEPTIONS=1 -debug-and-release -force-debug-info -platform win32-msvc -opensource -confirm-license -opengl es2

copy the above code into the bat file, open the cmd command line, and execute the bat file on the command line

When initializing the environment variables, I put all the software used in one directory for easy management, and the exit of cmd window will not affect the original environment variables of my system.

Let me explain the compilation parameters used above: the default is dynamic compilation

QT_NO_EXCEPTIONSMacro switch, closing Qt exception
-debug-and-releaseCompile debug and release versions
-force-debug-infoCreate symbol information for release version
-platform win32-msvcWin32 MSVC platform
-opensource -confirm-licenseOpen source version at compile time
-opengl es2opengl supporting ES2 API
-prefix %MY_INSTALL_PATH%After compilation, execute cmake insall to automatically copy to MY_INSTALL_PATH directory

After initializing the above environment, you can execute \configure --help, you can find more option information. I suggest you read it again.

When executing the bat file on the command line, you must carefully observe the output information. This is one of the paragraphs: it contains the version of the compiler. I was here before.

-- CMAKE_VERSION: "3.22.0"
-- CMAKE_HOST_SYSTEM: "Windows-10.0.19042"
-- CMAKE_SYSTEM: "Windows"
-- CMAKE_SYSTEM_VERSION: "10.0.19042"
-- CMAKE_C_COMPILER: "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.28.29910/bin/Hostx86/x86/cl.exe" (19.28.29920.0)
-- CMAKE_CXX_COMPILER: "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.28.29910/bin/Hostx86/x86/cl.exe" (19.28.29920.0)
-- MSVC_VERSION: "1928"

Look at the last tip

WARNING: QDoc will not be compiled, probably because libclang could not be located. This means that you cannot build the Qt documentation.
Either set CMAKE_PREFIX_PATH or LLVM_INSTALL_DIR to the location of your llvm installation.
On Linux systems, you may be able to install libclang by installing the libclang-dev or libclang-devel package, depending on your distribution.
On macOS, y-- Configuring incomplete, errors occurred!
ou can use Homebrew's llvm package.
You will also need to set the FEATURE_clang CMake variable to ON to re-evaluate this check.
WARNING: Clang-based lupdate parser will not be available. LLVM and Clang C++ libraries have not been found.
You will need to set the FEATURE_clangcpp CMake variable to ON to re-evaluate this check.
WARNING: QtWebEngine won't be built. node.js version 10.19 or later is required.
WARNING: QtPdf won't be built. node.js version 10.19 or later is required.

Qt is now configured for building. Just run 'cmake --build . --parallel'

Once everything is built, you must run 'cmake --install .'
Qt will be installed into 'D:/qt/qt-6.2.2/bin'

To configure and build other Qt modules, you can use the following convenience script:

If reconfiguration fails for some reason, try to remove 'CMakeCache.txt' from the build directory

The information here needs to be read carefully and some tips are given

  • QDoc, qtwebengine and qtpdf are not compiled
  • Tell you what you need next cmake -- build-- parallel
  • After the build is completed, you need cmake --install, Will be copied to the directory you specified earlier

I feel there should be no problem compiling here.

3. Problems encountered in the process

The environment configuration encountered in the compilation process is a major difficulty. I made a key introduction at the beginning, hoping to attract everyone's attention.

I'll talk about other problems, which has bothered me for a long time.

3.1 error encountered on CMD command line

You can see that when I set environment variables above, they are set separately, right. If you set it together, you will report an error: the input line is too long and the command syntax is incorrect.

The key is that if you put it into a bat file for execution, it does not have this error message.

I also found it by accident, because many cmd command line windows are opened, sometimes it is faster to copy the code directly. Just found this mistake.

3.2 why can't it be compiled into MT format?

Let me conclude: don't waste time compiling MT and MTd formats

Qt is compiled by MDd (debug version) and MD (release version) by default. After I compile, I will immediately test it in combination with libcef.

It was found that libcef was compiled using MTd and MT methods.

Once compiled, the following link problems are found:

Detected“ RuntimeLibrary"Mismatches for: Value“ MT_StaticDebug"Mismatch value“ MD_DynamicDebug"

I thought to myself that libcef I use the official compiled binary file, and I can't modify it anymore. So I had to go back and compile Qt in MT and MTd.

Then, I analyzed for a long time where cmake specified MDd and MD compilation options. Finally I found build The specified compilation options are found in ninja. I manually modify MDd to MTd and MD to MT. I also spent some time analyzing the build How did Ninja come into being? Ah... I didn't find out, so I gave up. Because I want to modify it directly from the source, not the generated file.

After 2 hours of compilation, it went well, but the problem came. When calling the exe of that translation, it will directly report:

Expression: __acrt_first_block == header

I checked the information and asked the same question on the Qt forum. Why not compile Qt in MT mode. One answer is: MD mode is more convenient for memory management.

For information about MT and MD, you can see this article

I think it can be summarized in one sentence: their memory management methods are different. MT must be applied by that module, and it must be released by that module. MD is unified management. In MT mode, an error will be reported if there is a mistake (this module applies for memory and other modules release memory). MD is a set of management memory, and there is no problem of cross module application and release memory.

4. Summary

In that sentence, the environment is very important.

The performance of my desktop machine is not bad. I only compiled the debug version, which took about 3 hours. I suggest that you compile debug first and then release in your spare time.

Finally, prepare a larger hard disk. When I compiled here, I spent a total of 78.2G, including all kinds of garbage files that failed to compile.

I ran a demo project by the way, no problem.

Topics: vs2019 Qt6