Bug #116779 Include <chrono> for system_clock
Submitted: 26 Nov 2024 7:22 Modified: 3 Dec 2024 23:15
Reporter: Sung Hui Chua Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:latest commit OS:Windows (Windows 11)
Assigned to: CPU Architecture:x86
Tags: build error, build from source, msvc

[26 Nov 2024 7:22] Sung Hui Chua
Description:
I work on Microsoft Visual C++ testing, where we regularly build popular open-source projects, including yours, with development builds of our compiler and libraries to detect and prevent shipping regressions that would affect you. This also allows us to provide advance notice of breaking changes, which is the case here.

Recently https://github.com/microsoft/STL/pull/5105, revealed an issue in mySQL.

Compiler error with this STL change:
C:\gitP\mysql\mysql-server\plugin\group_replication\libmysqlgcs\src\bindings\xcom\xcom\task.cc(388): error C3083: 'system_clock': the symbol to the left of a '::' must be a type
C:\gitP\mysql\mysql-server\plugin\group_replication\libmysqlgcs\src\bindings\xcom\xcom\task.cc(388): error C2039: 'now': is not a member of 'std::chrono'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\include\__msvc_chrono.hpp(286): note: see declaration of 'std::chrono'
C:\gitP\mysql\mysql-server\plugin\group_replication\libmysqlgcs\src\bindings\xcom\xcom\task.cc(388): error C3861: 'now': identifier not found
C:\gitP\mysql\mysql-server\plugin\group_replication\libmysqlgcs\src\bindings\xcom\xcom\task.cc(387): error C2672: 'std::chrono::duration_cast': no matching overloaded function found

This was assuming that including <thread> makes the chrono::system_clock type available, which is not guaranteed by the Standard. You need to explicitly include the chrono header in this file, and the error will be resolved.

How to repeat:
1. git clone https://github.com/mysql/mysql-server.git
2. cd mysql/mysql-server
3. mkdir build_amd64
3. cd build_amd64
4. cmake -G "Ninja" -DCMAKE_SYSTEM_VERSION=10.0.22621.0 -DWITH_SSL=C:\gitP\Microsoft\vcpkg\installed\x64-windows .. 
5. ninja

Suggested fix:
Add #include <chrono> to the source file.
[26 Nov 2024 7:23] Sung Hui Chua
Build log

Attachment: mysql.log (application/octet-stream, text), 725.64 KiB.

[10 Dec 2024 14:11] Jon Stephens
Documented fix as follows in the MySQL 8.4.4 and 9.2.0 changelogs:

    #include <chrono> was missing from
    plugin/group_replication/libmysqlgcs/src/bindings/xcom/xcom/task.cc
    even though std::chrono::duration_cast was referenced in this
    file.

Closed.