Issue
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?
Solution
It looks like major distros ship with a pkg-config file for mariadb called "mysqlclient.pc".
So you can do:
find_package(FindPkgConfig REQUIRED)
pkg_check_modules(mariadb REQUIRED IMPORTED_TARGET "mysqlclient")
and then link it to your program like so:
target_link_libraries(my_program PUBLIC PkgConfig::mariadb)
Answered By - Botje Answer Checked By - Katrina (WPSolving Volunteer)