0

How can i fix mysql errors in my position and use mysql without any problems at codeblock c++? When i include mysql.h, only "MYSQL", "MYSQL_RES", "MYSQL_ROW" class starts to work. Code (main.cpp):

#include <stdio.h>
#include "mysql/mysql.h"

MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "root";
char *password = "864630299";
char *database = "rpg";
conn = mysql_init(NULL);
// Connect to database
if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) {
  fprintf(stderr, "%s\n", mysql_error(conn));
  exit(1);
}
// send SQL query
if (mysql_query(conn, "show tables")) {
  fprintf(stderr, "%s\n", mysql_error(conn));
  exit(1);
}
res = mysql_use_result(conn);
// output table name
printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
  printf("%s \n", row[0]);
// close connection
mysql_free_result(res);
mysql_close(conn);

Errors:

undefined reference to 'mysql_init@4'
undefined reference to 'mysql_real_connect@32'
undefined reference to 'mysql_error'...

Settings: linker - none, search directories has: "\usr\lib\mysql\".

using mysql.h and other headers from "MySQL Server 5.5" include folder, which was copied and pasted to my project folder and used now as "#include "mysql/mysql.h".

For what reason my mysql commands dosen't work? : Example (mysql_query, mysql_real_connect...)

Thanks in advance.

Fixed myself by including in Settings->Compiler->Linker Settings->Add->libmysql.a, and including libmysql.dll to my project folder. :) Hope it helps for someone.

0 Answers0