I am trying to do mysql connection using c++, on Code::Blocks and mingw compiler on MSYS2.
Upon Compliling
g++.exe -Wall -fexceptions -c "D:\Programming Languages\03. Projects\cppdatabase\main.cpp" -o obj\Release\main.o
g++.exe -o bin\Release\cppdatabase.exe obj\Release\main.o
I am getting this error
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: obj\Release\main.o:main.cpp:(.text+0x13): undefined reference to `mysql_init'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: obj\Release\main.o:main.cpp:(.text+0x5d): undefined reference to `mysql_real_connect'
collect2.exe: error: ld returned 1 exit status
My Code
#include<iostream>
#include <mysql/mysql.h>
using namespace std;
int main()
{
MYSQL* conn;
conn = mysql_init(0);
conn = mysql_real_connect(conn, "localhost", "root", "", "db_test", 0, NULL, 0);
if(conn)
{
cout <<" Connection to database successful:"<<endl;
}
else{
cout<<"Connection unsuccessful"<<endl;
}
return 0;
}
I have this installed :
pacman -S mingw-w64-x86_64-libmariadbclient
I tried different methods available online , none of them helped.
Any suggestions ??