'Compiling C program using mysql under WSL
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
