#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 get linker error in codeblocks:
undefined reference to mysql_init
I used mysql_config --libs
in linker option and mysql_config --cflags
in compiler option.
I read somewhere i should add some libraries like libmysql.lib, but i cannot find this file on my PC (I am using Ubuntu 11.04 64bit).
compile your app with the command bellow
Setting -> Compiler and debugger -> Search directories -> Linker then Add and insert
/usr/lib/mysql/
This is for Linux environments only:
You will also need to add mysql-connector-c-6.1.3-linux-glibc2.5-x86_64/include/ in "Search directories" > "Compiler"
You will also need to add mysql-connector-c-6.1.3-linux-glibc2.5-x86_64/lib/ in "Search directories" > "Linker"
For windows:
-lmysql
MySQL Connector library can be found here: http://dev.mysql.com/downloads/connector/c/