0

Need Help:

I need to connect to MySQL 5.7 using connector/C on visual studio 2013 using a basic C program. I am getting errors linked to my_global.h.

I tried to find the solution on google but I am unsucessful yet.

My Steps:

  1. I downloaded MySQL 5.7 from MySQL webpage, and installed its msi installer sucessfully.

  2. I downloaded its Connector/C from MySQL webpage and installed its msi installer sucessfully. I found out that Connector/C is composed of header files (include files) and a library file (libmysql).

  3. I followed this tutorial (stackoverflow supported answer)to link library and include files into Visual Studio 2013.

  4. I write the following code on Visual Studio 2013

#include <my_global.h>
#include <mysql.h>

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

  if (conn == NULL)
  {
      printf("Error %u %s\n", mysql_errno(conn), mysql_error(conn));
      exit(1);
  }

  if (mysql_real_connect(conn, "localhost", "root", "asdfasdf", NULL, 0, NULL, 0) == NULL)
  {
      printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
      exit(1);
  }

  if (mysql_query(conn, "CREATE DATABASE testdb"))
  {
      printf("Error %u: %s", mysql_errno(conn), mysql_error(conn));
      exit(1);
  }

  mysql_close(conn);
  return 0;
}

It gives error: Error 2 error C2037: left of 'tv_nsec' specifies undefined struct/union 'timespec' c:\program files\mysql\mysql connector c 6.1\include\my_global.h 698 1 mysql

Can you help in following matters:

  1. I searched on google and was unable to find any specific tutorial. I searched google, youtube and stackoverflow. The MySQL Reference Manual isn't helping on getting started. Can you suggest me and support me in this problem?

  2. Is there any 1 (just one) ebook or book available on Connecting to MySQL using C programming?

I will be thankful for help!

1 Answers1

0

The linking method is absolutely correct. I also installed server mysql. I linked the mysql server libraries and it worked fine.