Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
 

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: C programming, Mysql api and CGI under Apache, Unreferenced functions mysql_init :(< Next Oldest | Next Newest >
steph291 Offline





Group: Members
Posts: 20
Joined: Oct. 2003
Posted: Sep. 27 2007,03:04 QUOTE

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;
}


--------------
smarchan291
Rouyn, Quebec, Canada
Proud Internet Coder
Back to top
Profile PM WEB 
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Sep. 27 2007,03:21 QUOTE

I'm guessing you would need to link the mysql (client) library during linking time (and dependencies)
Back to top
Profile PM 
jpeters Offline





Group: Members
Posts: 804
Joined: April 2006
Posted: Sep. 27 2007,15:29 QUOTE

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?
Back to top
Profile PM 
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Sep. 27 2007,16:09 QUOTE

No, those are run time static libs.  You'd want to link dev libs i.e. with -l
Back to top
Profile PM 
steph291 Offline





Group: Members
Posts: 20
Joined: Oct. 2003
Posted: Sep. 27 2007,23:42 QUOTE

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


--------------
smarchan291
Rouyn, Quebec, Canada
Proud Internet Coder
Back to top
Profile PM WEB 
4 replies since Sep. 27 2007,03:04 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

 
reply to topic new topic new poll
Quick Reply: C programming, Mysql api and CGI under Apache

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code