MySQL Connector/C++ 8.0 源码编译

时间:2019-03-15
本文章向大家介绍MySQL Connector/C++ 8.0 源码编译,主要包括MySQL Connector/C++ 8.0 源码编译使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

平台 

ubuntu 16.04

下载源码

访问 https://dev.mysql.com/downloads/connector/cpp/ ,选择source code 下载

依赖

编译 MySQL Connector/C++ 需要 依赖于openssl,mysql,cmake ,boost 等组件,需要事先安装

步骤

以下 以编译jdbc 静态库 为例,说明步骤。

1. 解压缩源码包

2. 在源码包之外建立构建目录 build 

3. 执行命令:(详细的编译配置可以参考官方文档:https://dev.mysql.com/doc/connector-cpp/8.0/en/connector-cpp-source-configuration-options.html#option_cmake_with_jdbc)

  cmake   源码包路径  -DCMAKE_INSTALL_PREFIX=mysql-connector/c++的安装目录  -DBUILD_STATIC=true    -DCMAKE_BUILD_TYPE=Release  -DWITH_JDBC=true -WITH_BOOST=boost的安装目录

4.  make && make install

5. 编译完成后在 安装目录下的 lib64 目录下会生成两个静态库 libmysqlcppconn8-static.a  和   libmysqlcppconn-static.a  。

按照官方文档的说法:

  • If you enabled the WITH_JDBC option to include the legacy JDBC connector in the build, the following additional library files are created.

    • If you build legacy dynamic libraries, they have these names:

      • libmysqlcppconn.so.7 (Unix)

      • libmysqlcppconn.7.dylib (macOS)

      • mysqlcppconn-7-vs14.dll (Windows)

    • If you build legacy static libraries, they have these names:

      • libmysqlcppconn-static.a (Unix, macOS)

      • mysqlcppconn-static.lib (Windows)

      这里因为只使用jdbc,所有选择使用libmysqlcppconn-static.a