Programming and Scripting :: C programming, Mysql api and CGI under Apache



Hi everyone,
My problem is I cannot communicate with mysql server using
C api and gcc. Every references to mysql functions return
errors.

I have modified my ld.so.conf to include the path to libmysqlclient (/opt/lampp/lib/mysql) then ldconfig.
but it's not helping, please help !!!

titou@server1:~$ gcc meteotest.c
/tmp/ccSjdnBl.o(.text+0x1d): In function `main':
: undefined reference to `mysql_init'
/tmp/ccSjdnBl.o(.text+0x43): In function `main':
: undefined reference to `mysql_connect'
/tmp/ccSjdnBl.o(.text+0x6c): In function `main':
: undefined reference to `mysql_select_db'
/tmp/ccSjdnBl.o(.text+0x7e): In function `main':
: undefined reference to `mysql_close'
/tmp/ccSjdnBl.o(.text+0xa3): In function `main':
: undefined reference to `mysql_query'
/tmp/ccSjdnBl.o(.text+0xb1): In function `main':
: undefined reference to `mysql_use_result'
/tmp/ccSjdnBl.o(.text+0xc5): In function `main':
: undefined reference to `mysql_fetch_row'
/tmp/ccSjdnBl.o(.text+0x10e): In function `main':
: undefined reference to `mysql_close'
collect2: ld returned 1 exit status

here's the source :
#include <stdio.h>
#include "/home/titou/mysql.h"

#define MYSQL_HOST "localhost"
#define MYSQL_DB "meteo"
#define MYSQL_LOGIN "duh!"
#define MYSQL_PASSWD "duh!"

int main() {
       MYSQL mysql;
       MYSQL_RES *result;
       MYSQL_ROW row;

       mysql_init(&mysql);
       if (!mysql_connect(&mysql,MYSQL_HOST,MYSQL_LOGIN,MYSQL_PASSWD)) {
               return -1;
       }
       if (mysql_select_db(&mysql,MYSQL_DB)) {
               mysql_close(&mysql);
               return -1;
       }
       mysql_query(&mysql,"SELECT * FROM meteoraw");
       result = mysql_use_result(&mysql);
       while((row = mysql_fetch_row(result))) {
               printf("%s",row[1]);
               fflush(stdout);
       }
       mysql_close(&mysql);
       return 0;
}

I'm guessing you would need to link the mysql (client) library during linking time (and dependencies)
Quote (^thehatsrule^ @ Sep. 26 2007,23:21)
I'm guessing you would need to link the mysql (client) library during linking time (and dependencies)

Would:

ln -s /opt/lampp/lib/mysql/*.so /usr/lib
 sudo ldconfig

do that, or something else?

No, those are run time static libs.  You'd want to link dev libs i.e. with -l
Thanks Guys !

I'm guessing that I should include "somewhere" the lib
(like in visual studio  with mssql or oracle api under windows)
for gcc calls... but I don't know how :(
and yes, maybe do a make and link the thing ...

But under unix/linux in console mode, it's a little bit tricky ...
I'm able to build simple CGI in C but I would love to be able
to do the trick with mysql under dsllinux.

I'm looking into this for several weeks and my project is WIP.
thanks for any replies

Next Page...
original here.