centOS7下使用cmake編譯mariadbpp出錯
- 2020 年 2 月 13 日
- 筆記
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
默認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