centOS7下使用cmake编译mariadbpp出错

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

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所在目录直接运行如下命令即可:

[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克隆源代码,然后按照如下方法编译源代码

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

比较关键的是git submodule update --init这条命令,运行后可以看到在mariadbpp源代码的external目录下多出了FindMariaDBClient.cmake文件,刚好是之前编译出现的缺少的文件,如下图所示:
FindMariaDBClient.cmake文件
默认mariadbpp编译出来的是静态库,如果需要动态库需要稍微修改下CMakeLists.txt文件的

# set up target
 add_library(mariadbclientpp ${mariadbclientpp_SOURCES} ${mariadbclientpp_PUBLIC_HEADERS} ${mariadbclientpp_PRIVATE    _HEADERS})

修改成

# 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

发布了103 篇原创文章 · 获赞 34 · 访问量 97万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览