Gossamer Forum
Home : General : Databases and SQL :

connecting mysql with c

Quote Reply
connecting mysql with c
hai,
i installed mysql3.23.49-3 in my redat 7.3 system. it's working well. i used mysql with php
and it also works well. but when i tried to use c api it shows some errors. here am showing the c code and the errors came.

//mysqlcon.c
#include <sys/time.h>
#include <stdio.h>
#include "usr/include/mysql/mysql.h"

int main(char **args)
{
MYSQL_RES *result;
MYSQL_ROW row;
MYSQL *connect,mysql;
int state;

//upto this line it works well.
mysql_init(&mysql);
}

error message came when i typed "gcc mysqlcon.c" command from the shell is given below.

/tmp/ccgfkaiz.o: In function 'main':
/tmp/ccgfkaiz.o(.text+0x14): undefined reference to 'mysql_init'
collect2: Id returned 1 exit status

please give me an instruction to solve this problem. when i tried with other c api's like
mysql_real_connect() etc.. same tyoe of problems arrived.
please note, i am just a beginner to the programming world.
thanks in advance
Quote Reply
Re: [rahulmb] connecting mysql with c In reply to
Try:

Code:
gcc mysqlcon.c -L/path/to/dir/of/libmysqlclient.so -lmysqlclient -o mysqlcon

Typically you can use "mysql_config --libs" to find out what to pass gcc