mariadbpp is the mariadb library of C++. Recently compiled mariadbpp under CentOS7 always fails. The error message is as follows:
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
I have installed the mariadb database using yum under the CentOS7 system, including the C language library of mariadb mariadb-connector-c
Installing mariadb-connector-c is very simple. Just run the following command in the directory where mariadb-connector-c is located:
[ 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
At the beginning, I downloaded the zip archive of mariadbpp directly from github, and then compiled with cmake in the same way as above and always reported an error.
Finally, use google to find a Russian question on stackoverflow Connect MariaDB in C++
On github https://github.com/viaduck/mariadbpp
I directly use git to clone the source code in CentOS7, and then compile the source code as follows
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
The default mariadbpp compiled is a static library, if you need a dynamic library, you need to slightly modify the CMakeLists.txt file
# set up target
add_library(mariadbclientpp ${mariadbclientpp_SOURCES} ${mariadbclientpp_PUBLIC_HEADERS} ${mariadbclientpp_PRIVATE _HEADERS})
changed to
# set up target
add_library(mariadbclientpp SHARED ${mariadbclientpp_SOURCES} ${mariadbclientpp_PUBLIC_HEADERS} ${mariadbclientpp_PRIVATE _HEADERS})
Add a SHARED
By default, the static library file libmariadbclientpp.a is generated in the /usr/local/lib/ directory, and the dynamic library file libmariadbclientpp.so is generated in the /usr/local/lib/ directory after modification.
In this way, you can use mariadbpp library to write C++ code to operate mysql or mariadb database.
Reference materials:
1、 mariadbpp
2、[ Connect MariaDB in C++](https://ru.stackoverflow.com/questions/975504/%D0%9F%D0%BE%D0%B4%D0%BA%D0%BB%D1%8E%D1% 87%D0%B8%D1%82%D1%8C-mariadb-%D0%BD%D0%B0-%D0%A1)
3、 "CMake Practice" Note 3: Building static libraries (.a) and dynamic libraries (.so) and how to use external shared libraries and header files
4、 mariadb-connector-c
Recommended Posts