前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >centOS7下使用cmake编译mariadbpp出错

centOS7下使用cmake编译mariadbpp出错

作者头像
ccf19881030
发布2020-02-13 11:12:36
1.1K0
发布2020-02-13 11:12:36
举报
文章被收录于专栏:ccf19881030的博客ccf19881030的博客

mariadbpp是C++的mariadb库,最近在CentOS7下编译mariadbpp总出错,错误信息如下:

代码语言:javascript
复制
CMake Error at CMakeLists.txt:17 (find_package):
 By not providing "FindMariaDBClient.cmake" in CMAKE_MODULE_PATH this
 project has asked CMake to find a package configuration file provided by
 "MariaDBClient", but CMake did not find one.

 Could not find a package configuration file provided by "MariaDBClient"
 with any of the following names:

   MariaDBClientConfig.cmake
   mariadbclient-config.cmake

 Add the installation prefix of "MariaDBClient" to CMAKE_PREFIX_PATH or set
 "MariaDBClient_DIR" to a directory containing one of the above files.  If
 "MariaDBClient" provides a separate development package or SDK, be sure it has been

我在CentOS7系统下已经使用yum安装了mariadb数据库,包括mariadb的C语言库mariadb-connector-c 安装mariadb-connector-c很简单,在mariadb-connector-c所在目录直接运行如下命令即可:

代码语言:javascript
复制
[root@VM_0_9_centos mariadb-connector-c]# 
[root@VM_0_9_centos mariadb-connector-c]# mkdir build
[root@VM_0_9_centos mariadb-connector-c]# cd build/
[root@VM_0_9_centos build]# ls
[root@VM_0_9_centos build]# cmake ..
-- The C compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
....................
[root@VM_0_9_centos build]# make 
[root@VM_0_9_centos build]# make  install

刚开始的时候我是直接从github上面下载的mariadbpp的zip压缩包,然后和上面相同的方式使用cmake编译总是报错。 最后使用google在stackoverflow上面找到一篇俄文的问题在C ++中连接MariaDB 在github上面https://github.com/viaduck/mariadbpp 我直接在CentOS7中使用git克隆源代码,然后按照如下方法编译源代码

代码语言:javascript
复制
Initialize Git submodules: git submodule update --init
Install mariadbclient or mysqlclient libraries.
Link against the mariadbclientpp CMake target in your project.
代码语言:javascript
复制
git clone https://github.com/viaduck/mariadbpp.git
cd mariadbpp
git submodule update --init
mkdir build
cd build
cmake ..
make 
make install

默认mariadbpp编译出来的是静态库,如果需要动态库需要稍微修改下CMakeLists.txt文件的

代码语言:javascript
复制
# set up target
 add_library(mariadbclientpp ${mariadbclientpp_SOURCES} ${mariadbclientpp_PUBLIC_HEADERS} ${mariadbclientpp_PRIVATE    _HEADERS})

修改成

代码语言:javascript
复制
# set up target
add_library(mariadbclientpp SHARED ${mariadbclientpp_SOURCES} ${mariadbclientpp_PUBLIC_HEADERS} ${mariadbclientpp_PRIVATE    _HEADERS})

即加了一个SHARED 默认在/usr/local/lib/目录下生成的是libmariadbclientpp.a静态库文件,修改后在/usr/local/lib/目录下生成的是libmariadbclientpp.so动态库文件。 这样就可以使用mariadbpp库,编写C++代码操作mysql或者mariadb数据库了。

参考资料: 1、mariadbpp 2、在C ++中连接MariaDB 3、《CMake实践》笔记三:构建静态库(.a) 与 动态库(.so) 及 如何使用外部共享库和头文件 4、mariadb-connector-c

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档