0

I am trying to interact with mariadb database using mariadb connector/c. I have installed mariadb connector using msi file from official site. But bin file of connector is empty. I am new to c coding, if someone knows the reason for bin file to be empty, please suggest me what I can do to solve this?

Following is the code:

#include <stdio.h>
#include <stdlib.h>
#include "C:\Program Files\MariaDB 10.6\include\mysql\mysql.h"



int main(int argc, char **argv)
{  
  MYSQL *con = mysql_init(NULL);

  if (con == NULL) 
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      exit(1);
  }

  if (mysql_real_connect(con, "localhost", "root", "admin", 
          NULL, 0, NULL, 0) == NULL) 
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      mysql_close(con);
      exit(1);
  }  

  if (mysql_query(con, "CREATE DATABASE testdb")) 
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      mysql_close(con);
      exit(1);
  }

  mysql_close(con);
  exit(0);
}

Command I am using to compile is: gcc -o Dbcon.exe Dbcon.c -I"C:\Program Files\MariaDB\MariaDB Connector C 64-bit\include" -L"C:\Program Files\MariaDB\MariaDB Connector C 64-bit\lib" -lmariadb

I am getting error as: C:\Program Files\MariaDB\MariaDB Connector C 64-bit\lib\libmariadb.dll: file not recognized: File format not recognized

What wrong I am doing? Can anyone suggest the right way to do this?

3
  • Do you build with msys + gcc? Commented Feb 15, 2023 at 6:56
  • I am building it with gcc only
    – Harshal
    Commented Feb 15, 2023 at 6:59
  • In normal command prompt/powershell (without mingw / cygwin) ? Commented Feb 15, 2023 at 7:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.