如何编译C++使用cmake和-l/usr/include/mariadb/mysql -lmariadbclient
我的C ++文件包括Mariadb/mysql.h,如下。
#include <mariadb/mysql.h>
我将C ++文件编译如下。
g++ -std=c++2a -g main.cpp -o main -lmariadbclient
它可以正常工作。但是,如果我想使用cmakelists.txt编译我的C ++文件。如何使用cmake将C ++源代码与-lmariaDbClient
编译?
My C++ file includes the mariadb/mysql.h as following.
#include <mariadb/mysql.h>
I compile my C++ file as following.
g++ -std=c++2a -g main.cpp -o main -lmariadbclient
It works fine. But if I want to compile my C++ file using CMakeLists.txt. How to compile the C++ source code with -lmariadbclient
using CMake?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来像Mariadb的PKG-Config文件一样,称为“ mysqlclient.pc”。
因此,您可以
这样做:然后将其链接到您的程序:
It looks like major distros ship with a pkg-config file for mariadb called "mysqlclient.pc".
So you can do:
and then link it to your program like so:
在主cmakelists.txt中添加以下内容。
在与主
cmakelists.txt
的同一目录中,创建目录cmake-modules
并创建文件findmariaiadbclient.cmake.cmake
> cmake-modules
目录。在
findmariadbclient.cmake
文件中添加以下内容。Add the following in the main CMakeLists.txt.
In the same directory as the main
CMakeLists.txt
, create the directorycmake-modules
and create the fileFindMariaDBClient.cmake
in thecmake-modules
directory.Add the following in the
FindMariaDBClient.cmake
file.