Mysql with C ++ error: undefined link to mysql_init

#include <stdlib.h>
#include <mysql.h>

#include <my_global.h>


int main (int argc, char *argv[])
{

MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;

char *server = "127.0.0.1";
char *user = "root";
char *password = "1386";
char *database = "OurDB";

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(0);
}

  return 0;
}

      

and I am getting linker error in code blocks:

undefined reference to mysql_init

      

I have used mysql_config --libs

in linker option and mysql_config --cflags

compiler option.

I read somewhere, I have to add some libraries like libmysql.lib, but I cannot find this file on my PC (I am using Ubuntu 11.04 64 bit).

+3


source to share


3 answers


Setting -> Compiler and Debugger -> Search Directories -> Linker then Add and Paste/usr/lib/mysql/



0


source


This only applies to Linux environments:

In the "Project Build Options"> "Linker Settings" tab> In the "Other Linker" section add -lmysqlclient

enter image description here

You will also need to add mysql-connector-c-6.1.3-linux-glibc2.5-x86_64 / include / to Search Directories > Compiler

enter image description here



You will also need to add mysql-connector-c-6.1.3-linux-glibc2.5-x86_64 / lib / to Search Directories > Linker

enter image description here

For windows:

-lmysql

The MySQL Connector library can be found here: http://dev.mysql.com/downloads/connector/c/

+3


source


compile your application with the below command

gcc -o test  -L/usr/lib/mysql -lmysqlclient test.c

      

+2


source







All Articles