C programming, Mysql api and CGI under ApacheForum: Programming and Scripting Topic: C programming, Mysql api and CGI under Apache started by: steph291 Posted by steph291 on Sep. 27 2007,03:04
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; } Posted by ^thehatsrule^ on Sep. 27 2007,03:21
I'm guessing you would need to link the mysql (client) library during linking time (and dependencies)
Posted by jpeters on Sep. 27 2007,15:29
Would: ln -s /opt/lampp/lib/mysql/*.so /usr/lib sudo ldconfig do that, or something else? Posted by ^thehatsrule^ on Sep. 27 2007,16:09
No, those are run time static libs. You'd want to link dev libs i.e. with -l
Posted by steph291 on Sep. 27 2007,23:42
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 |