使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)

Building MySQL Connector/C++ from source with cmake fails (conflicts with a previous declaration)

本文关键字:冲突 声明 失败 C++ 源代码 cmake 构建 MySQL 连接器 使用      更新时间:2023-10-16

我正试图使用gcc-8.1.0和cmake 3.6.2编译MySQL连接器/C++8.0.12,因为apt包似乎是为gcc-4.9编译的,当与gcc-8.1.10编译的程序一起使用时会崩溃(但与gcc-4.9汇编的程序一起工作(。

来自MySQL文档:

即使编译器版本发生微小更改也可能导致问题。如果您获得的错误消息怀疑与二进制不兼容有关,请使用与构建和链接应用程序相同的编译器和链接器从源代码构建Connector/C++。

当我尝试从这里描述的源代码构建连接器时:

git clone https://github.com/mysql/mysql-connector-cpp.git
mkdir cppconn
cd cppconn
cmake /home/pi/mysql-connector-cpp
# Everything looks fine except for:
Protobuf include path: /home/pi/mysql-connector-cpp/cdk/protobuf/protobuf-2.6.1/src
...
-- Performing Test HAVE_IS_SAME - Failed
cmake --build . --target install --config Debug
# All lot of warings come up and then:
Scanning dependencies of target protobuf
...
[ 34%] Building CXX object CMakeFiles/protobuf.dir/protobuf-2.6.1/src/google/protobuf/text_format.cc.o
In file included from /home/pi/mysql-connector-cpp/cdk/protobuf/protobuf-2.6.1/src/google/protobuf/text_format.cc:37:
/usr/bin/gcc-8.1.0/include/c++/8.1.0/math.h:65:12: error: ‘constexpr bool std::isinf(double)’ conflicts with a previous declaration
using std::isinf;
^~~~~
In file included from /usr/include/features.h:374,
from /usr/bin/gcc-8.1.0/include/c++/8.1.0/arm-linux-gnueabihf/bits/os_defines.h:39,
from /usr/bin/gcc-8.1.0/include/c++/8.1.0/arm-linux-gnueabihf/bits/c++config.h:508,
from /usr/bin/gcc-8.1.0/include/c++/8.1.0/utility:68,
from /usr/bin/gcc-8.1.0/include/c++/8.1.0/algorithm:60,
from /home/pi/mysql-connector-cpp/cdk/protobuf/protobuf-2.6.1/src/google/protobuf/text_format.cc:35:
/usr/include/arm-linux-gnueabihf/bits/mathcalls.h:201:1: note: previous declaration ‘int isinf(double)’
__MATHDECL_1 (int,isinf,, (_Mdouble_ __value)) __attribute__ ((__const__));
^~~~~~~~~~~~
In file included from /home/pi/mysql-connector-cpp/cdk/protobuf/protobuf-2.6.1/src/google/protobuf/text_format.cc:37:
/usr/bin/gcc-8.1.0/include/c++/8.1.0/math.h:66:12: error: ‘constexpr bool std::isnan(double)’ conflicts with a previous declaration
using std::isnan;
^~~~~
In file included from /usr/include/features.h:374,
from /usr/bin/gcc-8.1.0/include/c++/8.1.0/arm-linux-gnueabihf/bits/os_defines.h:39,
from /usr/bin/gcc-8.1.0/include/c++/8.1.0/arm-linux-gnueabihf/bits/c++config.h:508,
from /usr/bin/gcc-8.1.0/include/c++/8.1.0/utility:68,
from /usr/bin/gcc-8.1.0/include/c++/8.1.0/algorithm:60,
from /home/pi/mysql-connector-cpp/cdk/protobuf/protobuf-2.6.1/src/google/protobuf/text_format.cc:35:
/usr/include/arm-linux-gnueabihf/bits/mathcalls.h:234:1: note: previous declaration ‘int isnan(double)’
__MATHDECL_1 (int,isnan,, (_Mdouble_ __value)) __attribute__ ((__const__));

文件规定的要求:

  • 一个支持C++11的C++编译器。如果是gcc,它必须至少是4.8版本。这些编译器已经过测试:gcc 4.8.5、5.4.0、6.3.0、6.3.1、7.2.1、7.3.0、8.1.1、clang 9.0.0、MS Visual Studio 2015(目前~8.1.0(
  • CMake 2.8.12或更高版本(目前-3.6.2(
  • 如果使用的C++标准库版本未实现UTF8转换器(codecvt_UTF8(,则Boost 1.59或更高版本。构建传统连接器时也需要Boost(请参阅下文((据我所知,libstdc++.so.6.0.25支持codecvt_utf8(
  • 如果连接器是使用OpenSSL构建的,则为OpenSSL 1.0.x版本。连接器/C++可以使用WolfSSL 3.14.0或更新版本来构建,而不是OpenSSL(当前版本-1.0.1(
  • MySQL 8.0客户端库,如果构建遗留连接器(请参见下文((无需(

其他信息:

  • 使用运行Raspbian的Raspberry Pi 2b
  • libstdc++版本为6.0.25
  • Protobuf版本似乎是2.6.1(待构建(

提前感谢-Minding

解决方案是使用以下命令正确安装gcc:

cp -a gcc-*version*/bin/. /usr/bin/
cp -a gcc-*version*/lib/. /usr/lib/
# ... (for all sub directories)

它只是将源文件夹的所有文件复制到目标文件夹。

感谢@Matthieu Brucher告诉我安装错误以及如何正确安装。