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

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

我正在尝试使用 gcc-8.1.0 和 cmake 3.6.2 编译 MySQL Connector/C++ 8.0.12,因为 apt 包似乎是为 gcc- 编译的4.9 并在与 gcc-8.1.0 编译程序一起使用时崩溃(但适用于 gcc-4.9 编译程序)。

来自MySQL Documentation

Even a small change in the compiler version can cause problems. If you obtain error messages that you suspect are related to binary incompatibilities, build Connector/C++ from source, using the same compiler and linker that you use to build and link your application.

当我尝试按照 here 所述从源构建连接器时:

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__));

documentation规定的要求:

附加信息:

提前致谢。 -心灵

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

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

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

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