It's in the title, I want to create a program in C which connects to my MySQL database which is hosted locally with MAMP, I use as IDE CLion and I'm on Windows. I also use the MySQL API that I installed in my MinGW directory
So to do this I use this code:
#include <stdio.h>
#include <stdlib.h>
#include <winsock.h>
#include <MYSQL/mysql.h>
int main(int argc, char **argv)
{
printf("\nhello");
MYSQL *con = mysql_init(NULL);
if (con == NULL)
{
fprintf(stderr, "%s\n", mysql_error(con));
exit(1);
}
printf("\ntest");
if (mysql_real_connect(con, "localhost", "root", "root",
"perfect-concierge", 3307, NULL, 0) == NULL)
{
fprintf(stderr, "%s\n", mysql_error(con));
mysql_close(con);
exit(1);
}
printf("\ntest2");
if (mysql_query(con, "CREATE DATABASE testdb"))
{
fprintf(stderr, "%s\n", mysql_error(con));
mysql_close(con);
exit(1);
}
printf("\ntest3");
mysql_close(con);
exit(0);
}
"Tests" are there to see where there would be an error. And I use this CMakeFile.txt :
cmake_minimum_required(VERSION 3.12)
project(Test-MySQL C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_FLAGS "-Wall")
add_library(libmysql SHARED IMPORTED)
set_target_properties(
libmysql
PROPERTIES LINKER_LANGUAGE C
IMPORTED_IMPLIB "C:/MinGW/lib/libmysqlclient.a")
link_directories("C:/MinGW/lib")
add_executable(Test-MySQL main.c)
target_link_libraries(Test-MySQL libmysql)
(PS : It is not me who made this CMakeFile but the one who gave me this example of connection to a MySQL database)
But when I execute this code the program compiles well, it runs then I get this error :
Process finished with exit code -1073741515 (0xC0000135)
Without anything else. I tried to just change the main function and just keep printf("\nhello");
and the program worked correctly, but just add MYSQL *con = mysql_init(NULL);
send me this error again
Thank you in advance for the time you will take to help me.