dbTalk Databases Forums  

mysql in c++ initialize error occurs a simple program is executed in redhat9.0 , using gcc 3.2.2 compiler version ...

comp.databases comp.databases


Discuss mysql in c++ initialize error occurs a simple program is executed in redhat9.0 , using gcc 3.2.2 compiler version ... in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
yogesh
 
Posts: n/a

Default mysql in c++ initialize error occurs a simple program is executed in redhat9.0 , using gcc 3.2.2 compiler version ... - 02-15-2007 , 03:50 AM






mysql in c++ initialize error occurs a simple program is executed in
redhat9.0 , using gcc 3.2.2 compiler version ...

#include <stdio.h>
#include <mysql.h>
#include <string.h>

int main()
{
MYSQL* mysql;
MYSQL_RES* res;
MYSQL_ROW row;
char query[80];

mysql = mysql_init( NULL );

if( mysql == NULL ) {

mysql_real_connect( mysql, "localhost", "username",
"password","dbname", 0, "/tmp/mysql.sock", 0 );

sprintf( query, "SELECT * FROM tablename" );
mysql_real_query( mysql, query, (unsigned
int)strlen(query) );
res = mysql_use_result( mysql );

while( row = mysql_fetch_row( res ) ) {
printf( "%s %s\n", row[0], row[1] );
}

mysql_free_result( res );
mysql_close( mysql );
}

else {
printf( "mysql_init returned NULL\n" );
}
return 0;
}

"n1.cpp" 34L, 656C written

if i run the code iam getting the error as follows

[root@localhost yog]# gcc n1.cpp
/tmp/cccUdCdL.o(.text+0x16): In function `main':
: undefined reference to `mysql_init'
/tmp/cccUdCdL.o(.text+0x4b): In function `main':
: undefined reference to `mysql_real_connect'
/tmp/cccUdCdL.o(.text+0x81): In function `main':
: undefined reference to `mysql_real_query'
/tmp/cccUdCdL.o(.text+0x8f): In function `main':
: undefined reference to `mysql_use_result'
/tmp/cccUdCdL.o(.text+0xa0): In function `main':
: undefined reference to `mysql_fetch_row'
/tmp/cccUdCdL.o(.text+0xd8): In function `main':
: undefined reference to `mysql_free_result'
/tmp/cccUdCdL.o(.text+0xe6): In function `main':
: undefined reference to `mysql_close'
/tmp/cccUdCdL.o(.eh_frame+0x11): undefined reference to
`__gxx_personality_v0'
collect2: ld returned 1 exit status


Reply With Quote
  #2  
Old   
greg.fenton
 
Posts: n/a

Default Re: mysql in c++ initialize error occurs a simple program is executed in redhat9.0 , using gcc 3.2.2 compiler version ... - 02-16-2007 , 11:59 AM






On Feb 15, 4:50 am, "yogesh" <yogeshkum... (AT) gmail (DOT) com> wrote:
Quote:
[root@localhost yog]# gcc n1.cpp
/tmp/cccUdCdL.o(.text+0x16): In function `main':
: undefined reference to `mysql_init'

Just a gut-reaction guess, but don't you need to add "-lmysql" or some
similar library reference so that the linker knows where those
functions are?

greg.fenton



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.