0

I'm newbie with WSL and there is a lot of time spent from my last C compilation. I have a small C program which compile and execute with WSL (in the CLion dev environment, which use CMake to compile and link)

#include <stdio.h>

int main()
{
   char server[16] = "localhost"; char username[16] = "root";
   char password[16] = ""; char database[16] = "sports";

   char *conn = NULL;
   if (conn == NULL) {
      printf("MySQL: initialisation de %s a echouee", database);
      return 1;
   }
}

then i'm trying to add some database functionalities; a minimal one is connecting to the database

#include "include/mysql.h"
#include <stdio.h>

int main()
{
   char server[16] = "localhost"; char username[16] = "root";
   char password[16] = ""; char database[16] = "sports";

   MYSQL* conn = mysql_init(NULL);
   if (conn == NULL) {
      printf("MySQL: initialisation de %s a echouee", database);
      return 1;
   }
}

Here, I need to get the mysql environment and to link to the lib. My reference is: Link to the MYSQL C Api doc My understanding is that I need to link my code with libmysqlclient.a. But, I'm not able to find the library. I've done:

sudo apt update
sudo apt install mysql-server

But then, I'm not able to find the mysql library and and include(s) file(s) and to understand how to link it. I've tried:

find_package(MYSQL REQUIRED)

in the Cmake file, but without success. Any helps, advices, pointers are welcome.

Shadow
  • 33,525
  • 10
  • 51
  • 64
  • "My understanding is that I need to link my code with libmysqlclient.a. But, I'm not able to find the library." - Searching for the Ubuntu package with a library is not so difficult: https://packages.ubuntu.com/search?keywords=libmysqlclient. It founds [libmysqlclient-dev](https://packages.ubuntu.com/focal/libmysqlclient-dev). – Tsyvarev Feb 23 '22 at 22:59
  • Thank's. But, it is just a step. So, I also done sudo apt install libmysqlclient-dev (which works) and then? where is the library? where are the include files? why the find_package cmake command doesn't find the mysql package and how to go forward. I'm reading pages and pages of documentation and I'm still stuck – user10867087 Feb 24 '22 at 00:22
  • I think there are in /usr/include/mysql and /usr/lib/x86_64-linux-gnu. So, I can perhaps avoid to expect an answer from the find_package command. Then, I will try to specify directly the link in my cmake file – user10867087 Feb 24 '22 at 00:39
  • There is no ready-made support for `find_package(MySQL)`, neither in CMake itself (it doesn't provide script `FindMySQL.cmake`), nor in MySQL package (it doesn't provide script `MySQLConfig.cmake`). However, it is not so difficult to write script `FindMySQL.cmake` and ship it with your project. See [that question](https://stackoverflow.com/questions/47157432/where-is-findmysql-cmake-in-recent-linux-distributions) for more info. – Tsyvarev Feb 24 '22 at 07:06

0 Answers0