MySQL 源码阅读 —— 问题 expanded from macro MYSQL_VERSION_MAJOR
source link: https://segmentfault.com/a/1190000040643930
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
MySQL 源码阅读 —— 问题 expanded from macro MYSQL_VERSION_MAJOR
在执行
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 的 [email protected],找到了一个 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 情况,可以参考下这个项目:
所以产生问题的条件是:
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
感谢您的阅读,觉得内容不错,点个赞吧 😆
原文地址: https://shockerli.net/post/mysql-source-version-conflict-in-cpp-11/
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK