I’m writing a console application in kdevelop (integrated with cmake) in which I want to connect to mysql. I have installed libmysqlclient16-dev. My main.cpp file looks like this:
#include <stdlib.h>
#include <iostream>
#include <mysql/mysql.h>
int main(int argc, char **argv) {
MYSQL *conn_ptr;
conn_ptr = mysql_init(NULL);
if (!conn_ptr) {
std::cout << "mysql init failed\n";
exit(1);
}
conn_ptr = mysql_real_connect (conn_ptr, "localhost", "user", "pass", "db", 0, NULL, 0);
if (conn_ptr) {
std::cout << "connection success\n";
} else {
std::cout << "connection failed\n";
}
mysql_close(conn_ptr);
return 0;
}
and it compiles and works correctly, when I compile it manually:
g++ main.cpp -lmysqlclient -o main
But I want to include it into cmake somehow. The CMakeLists.txt, generated by kdevelop, looks like the following:
project(finances)
add_executable(finances main.cpp)
What should I add to cmake to make it include mysqlclient library?
Seems to work.