问题形容
在执行
make
构建时可能会报错
Building C object storage/myisam/CMakeFiles/myisam.dir/mi_rfirst.c.o
In file included from /path/to/mysql-5.7.35/storage/perfschema/cursor_by_account.cc:28:
In file included from /path/to/mysql-5.7.35/include/my_global.h:57:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/math.h:309:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/type_traits:417:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/cstddef:37:
/path/to/mysql-5.7.35/version:1:1: error: expected unqualified-id
MYSQL_VERSION_MAJOR=5
^
/path/to/mysql-5.7.35/include/my_config.h:404:29: note: expanded from macro 'MYSQL_VERSION_MAJOR'
#define MYSQL_VERSION_MAJOR 5
^
起因排查
通过 Homebrew 的 mysql@5.7.rb,找到了一个 PATCH。
在 MySQL 的 Commit 记录 Bug #31466846 RENAME THE VERSION FILE TO MYSQL_VERSION 找到了答案:
Bug #31466846 RENAME THE VERSION FILE TO MYSQL_VERSION
With new versions of boost, the build is broken on windows.
<version> is a header file which is part of C++11, but on win we
include our own VERSION instead, and the build breaks.
The solution is 'git mv VERSION MYSQL_VERSION', and adapt
cmake code accordingly.
Change-Id: I5211cf41fa83e879a25d4110dbb8933cd58da2f9
8.0
mysql-cluster-8.0.26 mysql-cluster-8.0.25 mysql-cluster-8.0.24 mysql-cluster-8.0.23 mysql-cluster-8.0.22 mysql-8.0.26 mysql-8.0.25 mysql-8.0.24 mysql-8.0.23 mysql-8.0.22
Tor Didriksen committed on 10 Jun 2020
1 parent 6653b43 commit 51675ddb41661163c23e802a3e5eedb1344ce023
大略意思是:
version
是C++11
的一个头文件,但 MySQL 以往都是用VERSION
示意的版本号,在引入文件时又因 macOS 不辨别文件大小写,产生了抵触,导致编译时报错中断。
在 macOS Big Sur 11.5
中的 SDK 是 MacOSX11.3.sdk
,的确在 include
下存在 version
这么个头文件:
/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/version
但在 MacOSX11.1.sdk
及更老版本中,却没有这个文件。
每个版本的 Mac SDK 状况,能够参考下这个我的项目:
https://github.com/phracker/M…
所以产生问题的条件是:
MacOSX11.1.sdk
及以下零碎中编译MySQL 8.0.21
及更老版本(包含5.7.*
)时, 没问题;MacOSX11.3.sdk
及以上版本中编译MySQL 8.0.22
及更新版本时,没问题;- 但
MacOSX11.3.sdk
及以上版本中编译MySQL 8.0.21
及更老版本(包含5.7.*
)时, 有问题;
SDK 版本与 XCode
或 xcode-select
有关系。
能够通过 /Library/Developer/CommandLineTools/SDKs
目录来判断 SDK 版本。
解决方案
MySQL 8.0.22
及更新版本,官网曾经批改了,但老版本怎么办?就按官网的形式批改下即可。
在执行 cmake
前,先批改 2 个中央:
- 文件
VERSION
重命名为MYSQL_VERSION
- 文件
cmake/mysql_version.cmake
中 2 处代码,VERSION
替换为MYSQL_VERSION
diff --git a/cmake/mysql_version.cmake b/cmake/mysql_version.cmake
index 43d731e..3031258 100644
--- a/cmake/mysql_version.cmake
+++ b/cmake/mysql_version.cmake
@@ -31,7 +31,7 @@ SET(DOT_FRM_VERSION "6")
# Generate "something" to trigger cmake rerun when VERSION changes
CONFIGURE_FILE(- ${CMAKE_SOURCE_DIR}/VERSION
+ ${CMAKE_SOURCE_DIR}/MYSQL_VERSION
${CMAKE_BINARY_DIR}/VERSION.dep
)
@@ -39,7 +39,7 @@ CONFIGURE_FILE(MACRO(MYSQL_GET_CONFIG_VALUE keyword var)
IF(NOT ${var})
- FILE (STRINGS ${CMAKE_SOURCE_DIR}/VERSION str REGEX "^[]*${keyword}=")
+ FILE (STRINGS ${CMAKE_SOURCE_DIR}/MYSQL_VERSION str REGEX "^[]*${keyword}=")
IF(str)
STRING(REPLACE "${keyword}=" "" str ${str})
STRING(REGEX REPLACE "[].*" ""str"${str}")
写好的脚本间接用:
mv VERSION MYSQL_VERSION
sed -i '''s|${CMAKE_SOURCE_DIR}/VERSION|${CMAKE_SOURCE_DIR}/MYSQL_VERSION|g' cmake/mysql_version.cmake
参考资料
- Homebrew/homebrew-core/Formula/mysql@5.7.rb
- mysql/mysql-server@Bug #31466846 RENAME THE VERSION FILE TO MYSQL_VERSION
感谢您的浏览,感觉内容不错,点个赞吧 😆
原文地址: https://shockerli.net/post/mysql-source-version-conflict-in-cpp-11/