I am trying to connect c++ to a mysql database and get this error
undefined reference to `mysql_init'
undefined reference to `mysql_real_connect'
my code is
#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "mysql.h"
int main(){
MYSQL* conn;
MYSQL_ROW row;
MYSQL_RES * res;
conn = mysql_init(0);
conn = mysql_real_connect(conn, "localhost", "root", "", "cpp", 0, NULL, 0);
if(conn){
std::cout << "Connected to database successfully";
} else {
std::cout << "Connection failed...";
exit(0);
}
return 0;
}
I am compiling with
g++ main.cpp
I have included all header files in the same directory
This stack overflow answer did not work for me
Mysql with C++ error: undefined reference to mysql_init
I am on windows 11