OpenEuler22.03 SP3编译MySQL5.7版本时,常规编译大概率会报错,这是因为OpenEuler系统虽然兼容红帽8.x系列,但是里面的软件包组改动过多,经常会出现编译某个软件时报错。
在OpenEuler22.03 SP3版本中,默认的gcc已经变成了10的版本,但是在其它8.x系列系统中,比如almalinux、rockylinux等,gcc都是8的版本,所以因为gcc版本的原因,编译各种软件可能存在一些问题。
本文以MySQL5.7编译为例,解决在编译中可能会遇到的问题,希望本文提供的一些思路方法,可以为大家解决一些相关的问题。
问题一:
默认MySQL5.7使用cmake编译的情况下,可能会看到如下报错,这是由于gcc版本的原因。
/usr/bin/ld: CMakeFiles/mysql_ssl_rsa_setup.dir/mysql_ssl_rsa_setup.cc.o: in function `execute_command(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': mysql-5.7.44/client/mysql_ssl_rsa_setup.cc:182: undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()' /usr/bin/ld: CMakeFiles/mysql_ssl_rsa_setup.dir/mysql_ssl_rsa_setup.cc.o: in function `X509_key::X509_key(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)': mysql-5.7.44/client/mysql_ssl_rsa_setup.cc:313: undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()' /usr/bin/ld: CMakeFiles/mysql_ssl_rsa_setup.dir/mysql_ssl_rsa_setup.cc.o: in function `RSA_priv::operator()(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': mysql-5.7.44/client/mysql_ssl_rsa_setup.cc:284: undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()' /usr/bin/ld: CMakeFiles/mysql_ssl_rsa_setup.dir/mysql_ssl_rsa_setup.cc.o: in function `RSA_pub::operator()(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': mysql-5.7.44/client/mysql_ssl_rsa_setup.cc:300: undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()' collect2: error: ld returned 1 exit status make[2]: *** [client/CMakeFiles/mysql_ssl_rsa_setup.dir/build.make:139: client/mysql_ssl_rsa_setup] Error 1 make[1]: *** [CMakeFiles/Makefile2:6398: client/CMakeFiles/mysql_ssl_rsa_setup.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs....
|----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 11 12 | /usr/bin/ld: CMakeFiles/mysql_ssl_rsa_setup.dir/mysql_ssl_rsa_setup.cc.o: in function `execute_command(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': mysql-5.7.44/client/mysql_ssl_rsa_setup.cc:182: undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()' /usr/bin/ld: CMakeFiles/mysql_ssl_rsa_setup.dir/mysql_ssl_rsa_setup.cc.o: in function `X509_key::X509_key(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)': mysql-5.7.44/client/mysql_ssl_rsa_setup.cc:313: undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()' /usr/bin/ld: CMakeFiles/mysql_ssl_rsa_setup.dir/mysql_ssl_rsa_setup.cc.o: in function `RSA_priv::operator()(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': mysql-5.7.44/client/mysql_ssl_rsa_setup.cc:284: undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()' /usr/bin/ld: CMakeFiles/mysql_ssl_rsa_setup.dir/mysql_ssl_rsa_setup.cc.o: in function `RSA_pub::operator()(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': mysql-5.7.44/client/mysql_ssl_rsa_setup.cc:300: undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()' collect2: error: ld returned 1 exit status make[2]: *** [client/CMakeFiles/mysql_ssl_rsa_setup.dir/build.make:139: client/mysql_ssl_rsa_setup] Error 1 make[1]: *** [CMakeFiles/Makefile2:6398: client/CMakeFiles/mysql_ssl_rsa_setup.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... |
解决:
不建议大家去手动编译gcc,这样可能会对系统造成一些问题,在其它一些8.x系统中,我们可以通过gcc-toolset-x包来临时改变gcc(https://blog.whsir.com/post-6114.html),因为OpenEuler系统的特殊性,不能以常规方式操作。
所以我们通过OpenEuler默认源中提供的gcc-toolset包,安装如下:
yum install gcc-toolset-12*
|---|------------------------------| | 1 | yum install gcc-toolset-12* |
这样就会把gcc12的版本装在系统中,不指定的情况下,gcc12是不生效的。
MySQL编译时,在cmake中指定gcc12的版本,增加内容如下:
cmake -DCMAKE_C_COMPILER=/opt/openEuler/gcc-toolset-12/root/usr/bin/gcc -DCMAKE_CXX_COMPILER=/opt/openEuler/gcc-toolset-12/root/usr/bin/g++
|---|---------------------------------------------------------------------------------------------------------------------------------------------| | 1 | cmake -DCMAKE_C_COMPILER=/opt/openEuler/gcc-toolset-12/root/usr/bin/gcc -DCMAKE_CXX_COMPILER=/opt/openEuler/gcc-toolset-12/root/usr/bin/g++ |
这样MySQL就使用gcc12的版本进行编译了。
问题二:
但是接下来编译可能还会报错,可能的报错内容如下
../../../extra/protobuf/protoc: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by ../../../extra/protobuf/protoc) make[2]: *** [rapid/plugin/x/CMakeFiles/mysqlx.dir/build.make:75: rapid/plugin/x/generated/protobuf_lite/mysqlx.pb.cc] Error 1 make[1]: *** [CMakeFiles/Makefile2:5421: rapid/plugin/x/CMakeFiles/mysqlx.dir/all] Error 2
|-------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | ../../../extra/protobuf/protoc: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by ../../../extra/protobuf/protoc) make[2]: *** [rapid/plugin/x/CMakeFiles/mysqlx.dir/build.make:75: rapid/plugin/x/generated/protobuf_lite/mysqlx.pb.cc] Error 1 make[1]: *** [CMakeFiles/Makefile2:5421: rapid/plugin/x/CMakeFiles/mysqlx.dir/all] Error 2 |
分析:
通过strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX,查看默认gcc模块中并没有3.4.29的版本
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_3.4.23
GLIBCXX_3.4.24
GLIBCXX_3.4.25
GLIBCXX_3.4.26
GLIBCXX_3.4.27
GLIBCXX_3.4.28
GLIBCXX_DEBUG_MESSAGE_LENGTH
通过gcc-toolset-12查看
strings /opt/openEuler/gcc-toolset-12/root/usr/lib64/libstdc++.so.6 | grep GLIBCXX
|---|-------------------------------------------------------------------------------------| | 1 | strings /opt/openEuler/gcc-toolset-12/root/usr/lib64/libstdc++.so.6 | grep GLIBCXX |
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_3.4.23
GLIBCXX_3.4.24
GLIBCXX_3.4.25
GLIBCXX_3.4.26
GLIBCXX_3.4.27
GLIBCXX_3.4.28
GLIBCXX_3.4.29
GLIBCXX_3.4.30
GLIBCXX_DEBUG_MESSAGE_LENGTH
所以在指定gcc-toolset-12版本gcc编译时,还需指定/opt/openEuler/gcc-toolset-12/root/usr/lib64/libstdc++.so.6,为了尽可能的减少对系统的改变,我们可以临时使用export使其变量生效。
export LD_LIBRARY_PATH=/opt/openEuler/gcc-toolset-12/root/usr/lib64:$LD_LIBRARY_PATH
|---|--------------------------------------------------------------------------------------| | 1 | export LD_LIBRARY_PATH=/opt/openEuler/gcc-toolset-12/root/usr/lib64:$LD_LIBRARY_PATH |
然后再次编译即可。
最后,推荐大家通过wlnmp一键安装包来安装,省略了编译过程,并且方便升级与卸载,安装MySQL5.7仅需两步
curl -fsSL "https://sh.wlnmp.com/wlnmp.sh" | bash yum install wmysql57
|-----|-------------------------------------------------------------------------| | 1 2 | curl -fsSL "https://sh.wlnmp.com/wlnmp.sh" | bash yum install wmysql57 |
更多内容详见wlnmp官网文档:https://www.wlnmp.com/install