Re: c program Bus Error (core dumped)
I can send the truss output of anyone can decipher it!! Regards Andy On Tue, 2005-01-11 at 13:05 +, Andy Ford wrote: Hi everyone. I have been trying to write a simple c program to access a local mySQL database (with the help of David Logan). With the following code I am getting the error ... Bus Error (core dumped) ... when I run my compiled program 'test'. [code] int main(char **args) { MYSQL_RES *result; MYSQL_ROW row; MYSQL *connection, mysql; int state; mysql_init(mysql); connection = mysql_real_connect(mysql, localhost, username, password, mydb, 0, NULL, 0); /* check for a connection error */ if( connection == NULL ) { printf(mysql_error(mysql)); return 1; } else { printf(Everything Cool with the connection\n); } state = mysql_query(connection, SELECT * from mytable); if( state ) { printf(mysql_error(connection)); return 1; } else { printf(Everything Cool with the query\n); } mysql_close(connection); printf(Done.\n); } [/code] The actual output is ... Everything Cool with the connection Everything Cool with the query Bus Error (core dumped) The 'Bus Error' I have Googled for but can't find a resolution. Any ideas? Thanks again.. Andy On Tue, 2005-01-11 at 12:05 +, Andy Ford wrote: Got it ... Thanks David gcc -m64 test.c -L/usr/local/mysql/lib -lmysqlclient -lsocket -lnsl -lm -o test .. seemed to work I get a 'Bus Error (core dumped)' when I run it - but that's a problem with the code!! Thanks Andy On Tue, 2005-01-11 at 22:23 +1100, Logan, David (SST - Adelaide) wrote: Hi Andy, I resolved the problem by reinstalling a 32bit version of mysql and the DBI worked fine after that. Looks like you are missing a library or 2, try nsl and socket. I think they have all the routines that you need to link against. You may also need an include or 2. All the routines have man pages that reference the libraries and includes required. Regards David Logan Database Administrator HP Managed Services 148 Frome Street, Adelaide 5000 Australia +61 8 8408 4273 - Work +61 417 268 665 - Mobile +61 8 8408 4259 - Fax -Original Message- From: Andy Ford [mailto:[EMAIL PROTECTED] Sent: Tuesday, 11 January 2005 9:37 PM To: Logan, David (SST - Adelaide) Cc: mysql@lists.mysql.com Subject: RE: compilation errors in mySQL C app Hi David Yes it is something like you say... file /usr/local/bin/gcc /usr/local/bin/gcc: ELF 32-bit MSB executable SPARC Version 1, dynamically linked, not stripped file /usr/local/bin/g++ /usr/local/bin/gcc: ELF 32-bit MSB executable SPARC Version 1, dynamically linked, not stripped isainfo -kv 64-bit sparcv9 kernel modules I got rid of the ELF issue with the -m64 option but still get the following errors... gcc -m64 test.c -L/usr/local/mysql/lib -lmysqlclient -o test Undefined first referenced symbol in file getpeername /usr/local/mysql/lib/libmysqlclient.a(viosocket.o) floor /usr/local/mysql/lib/libmysqlclient.a(password.o) socket /usr/local/mysql/lib/libmysqlclient.a(client.o) gethostbyname_r /usr/local/mysql/lib/libmysqlclient.a(client.o) setsockopt /usr/local/mysql/lib/libmysqlclient.a(viosocket.o) getservbyname /usr/local/mysql/lib/libmysqlclient.a(libmysql.o) connect /usr/local/mysql/lib/libmysqlclient.a(client.o) shutdown /usr/local/mysql/lib/libmysqlclient.a(viosocket.o) inet_ntoa /usr/local/mysql/lib/libmysqlclient.a(my_net.o) inet_addr /usr/local/mysql/lib/libmysqlclient.a(client.o) ld: fatal: Symbol referencing errors. No output written to test2 collect2: ld returned 1 exit status Getting there slowly Thanks Andy On Tue, 2005-01-11 at 21:42 +1100, Logan, David (SST - Adelaide) wrote: Hi Andy, Are you using a 64bit option to compile your program (I can't remember the option on gcc -m64 I think)? Looks like a 64bit mysql library trying to talk to a 32 bit program. I'm no expert but I had similar problems when I put a 64bit mysql on one of my Solaris boxen and tried to talk with a 32 bit perl implementation. Regards David Logan Database Administrator HP Managed Services 148 Frome Street, Adelaide 5000 Australia +61 8 8408 4273 - Work +61 417 268 665 - Mobile +61 8 8408 4259 - Fax -Original Message- From: Andy Ford [mailto:[EMAIL PROTECTED] Sent: Tuesday, 11 January 2005 8:59 PM To: mysql@lists.mysql.com Subject: compilation errors in mySQL C app Hi everyone I am trying
Re: c program Bus Error (core dumped)
Hi Andy, state = mysql_query(connection, SELECT * from mytable); *** ^^ if( state ) { printf(mysql_error(connection)); return 1; } else { printf(Everything Cool with the query\n); } // New code, retrieve resultset. result = mysql_store_result(connection); if (result) { printf( Return set: columns=%d, rows=%d \n, mysql_field_count(connection), mysql_num_rows(result)); mysql_free_result(__result); } else { printf(%s\n, mysql_error(connection)); return 1; } // New code - mysql_close(connection); printf(Done.\n); After doing a SELECT statement you should issue a mysql_store_result / mysql_use_result operation to flush the resultset returned (even an empty resultset). In fact, you should flush the resultset stream with every SQL statement that returns data like SELECT, SHOW, DESCRIBE, and the like. See the manual page on mysql_store_result for more information. Once in there, you can follow the directions about section 21.2.3.20 mysql_field_count() about using mysql_field_count to check in you need to flush the resultset. Do not forget to call mysql_free_result to free the memory allocated for the returned resultset. Hope this helps, maybe mysql_close(...) got confused by pending data from the server. One note though, you should NEVER use 'printf(whatever);' use 'printf(%s, whatever);' instead. If it happends to be some % inside whatever you will get coredumps. For instance, see what happends when in your program, mysql_error(connection) returns Please use %d to display integers. (Not a real MySQL error, obviously!! :-) Cheers, Jose Miguel. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: c program Bus Error (core dumped)
Thanks Jose ... but I still get the Bus Error message with the following code... int main(char **args) { MYSQL_RES *result; MYSQL_ROW row; MYSQL *connection, mysql; int state; int PORTNUM = 3306; mysql_init(mysql); connection = mysql_real_connect(mysql, localhost, root, 0sg0sb4Ig, oui, PORTNUM, NULL, 0); if( connection == NULL ) { printf(%s\n,mysql_error(mysql)); return 1; } else { printf(%s\n,Everything Cool with the connection); } state = mysql_query(connection, SELECT sysName from inv_device); result = mysql_store_result(connection); if (result) { printf( Return set: columns=%d, rows=%d \n, mysql_field_count(connection), mysql_num_rows(result)); mysql_free_result(result); } else { printf(%s\n, mysql_error(connection)); return 1; } mysql_close(connection); printf(%s\n,Done.); } Regards Andy On Tue, 2005-01-11 at 14:57 +0100, Jose Miguel Pérez wrote: Hi Andy, state = mysql_query(connection, SELECT * from mytable); *** ^^ if( state ) { printf(mysql_error(connection)); return 1; } else { printf(Everything Cool with the query\n); } // New code, retrieve resultset. result = mysql_store_result(connection); if (result) { printf( Return set: columns=%d, rows=%d \n, mysql_field_count(connection), mysql_num_rows(result)); mysql_free_result(__result); } else { printf(%s\n, mysql_error(connection)); return 1; } // New code - mysql_close(connection); printf(Done.\n); After doing a SELECT statement you should issue a mysql_store_result / mysql_use_result operation to flush the resultset returned (even an empty resultset). In fact, you should flush the resultset stream with every SQL statement that returns data like SELECT, SHOW, DESCRIBE, and the like. See the manual page on mysql_store_result for more information. Once in there, you can follow the directions about section 21.2.3.20 mysql_field_count() about using mysql_field_count to check in you need to flush the resultset. Do not forget to call mysql_free_result to free the memory allocated for the returned resultset. Hope this helps, maybe mysql_close(...) got confused by pending data from the server. One note though, you should NEVER use 'printf(whatever);' use 'printf(%s, whatever);' instead. If it happends to be some % inside whatever you will get coredumps. For instance, see what happends when in your program, mysql_error(connection) returns Please use %d to display integers. (Not a real MySQL error, obviously!! :-) Cheers, Jose Miguel. -- perl -e print qq^bIG VeRN ! ^^qq^#'#Yv#=D+ ^ This e-mail is private and may be confidential and is for the intended recipient only. If misdirected, please notify us by telephone and confirm that it has been deleted from your system and any copies destroyed. If you are not the intended recipient you are strictly prohibited from using, printing, copying, distributing or disseminating this e-mail or any information contained in it. We use reasonable endeavours to virus scan all e-mails leaving the Company but no warranty is given that this e-mail and any attachments are virus free. You should undertake your own virus checking. The right to monitor e-mail communications through our network is reserved by us. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: c program Bus Error (core dumped)
I can get something working however. int main(char **args) { MYSQL_RES *result; MYSQL_ROW row; MYSQL *connection, mysql; char *serverInfo=; int state; int PORTNUM = 3306; unsigned long int version; mysql_init(mysql); connection = mysql_real_connect(mysql, localhost, username, password, mydb, PORTNUM, NULL, 0); /* check for a connection error */ if( connection == NULL ) { /* print the error message */ printf(%s\n,mysql_error(mysql)); return 1; } else { printf(%s\n,Everything Cool with the connection); } printf(version = %ul\n, mysql_get_server_version(mysql)); mysql_close(connection); printf(%s\n,Done.); } ... prints out ... Everything Cool with the connection version = 40107l Done. ... but that is as far as I can go until I can fix the Bus Error Regards Andy On Tue, 2005-01-11 at 14:19 +, Andy Ford wrote: Thanks Jose ... but I still get the Bus Error message with the following code... int main(char **args) { MYSQL_RES *result; MYSQL_ROW row; MYSQL *connection, mysql; int state; int PORTNUM = 3306; mysql_init(mysql); connection = mysql_real_connect(mysql, localhost, root, 0sg0sb4Ig, oui, PORTNUM, NULL, 0); if( connection == NULL ) { printf(%s\n,mysql_error(mysql)); return 1; } else { printf(%s\n,Everything Cool with the connection); } state = mysql_query(connection, SELECT sysName from inv_device); result = mysql_store_result(connection); if (result) { printf( Return set: columns=%d, rows=%d \n, mysql_field_count(connection), mysql_num_rows(result)); mysql_free_result(result); } else { printf(%s\n, mysql_error(connection)); return 1; } mysql_close(connection); printf(%s\n,Done.); } Regards Andy On Tue, 2005-01-11 at 14:57 +0100, Jose Miguel Pérez wrote: Hi Andy, state = mysql_query(connection, SELECT * from mytable); *** ^^ if( state ) { printf(mysql_error(connection)); return 1; } else { printf(Everything Cool with the query\n); } // New code, retrieve resultset. result = mysql_store_result(connection); if (result) { printf( Return set: columns=%d, rows=%d \n, mysql_field_count(connection), mysql_num_rows(result)); mysql_free_result(__result); } else { printf(%s\n, mysql_error(connection)); return 1; } // New code - mysql_close(connection); printf(Done.\n); After doing a SELECT statement you should issue a mysql_store_result / mysql_use_result operation to flush the resultset returned (even an empty resultset). In fact, you should flush the resultset stream with every SQL statement that returns data like SELECT, SHOW, DESCRIBE, and the like. See the manual page on mysql_store_result for more information. Once in there, you can follow the directions about section 21.2.3.20 mysql_field_count() about using mysql_field_count to check in you need to flush the resultset. Do not forget to call mysql_free_result to free the memory allocated for the returned resultset. Hope this helps, maybe mysql_close(...) got confused by pending data from the server. One note though, you should NEVER use 'printf(whatever);' use 'printf(%s, whatever);' instead. If it happends to be some % inside whatever you will get coredumps. For instance, see what happends when in your program, mysql_error(connection) returns Please use %d to display integers. (Not a real MySQL error, obviously!! :-) Cheers, Jose Miguel. -- perl -e print qq^bIG VeRN ! ^^qq^#'#Yv#=D+ ^ This e-mail is private and may be confidential and is for the intended recipient only. If misdirected, please notify us by telephone and confirm that it has been deleted from your system and any copies destroyed. If you are not the intended recipient you are strictly prohibited from using, printing, copying, distributing or disseminating this e-mail or any information contained in it. We use reasonable endeavours to virus scan all e-mails leaving the Company but no warranty is given that this e-mail and any attachments are virus free. You should undertake your own virus checking. The right to monitor e-mail communications through our network is reserved by us. -- perl -e print qq^bIG VeRN ! ^^qq^#'#Yv#=D+ ^ -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: c program Bus Error (core dumped)
Hi Andy! but I still get the Bus Error message with the following code... int main(char **args) { MYSQL_RES *result; MYSQL_ROW row; MYSQL *connection, mysql; int state; int PORTNUM = 3306; [...] Andy, I have copied and pasted your code into a fresh new check.cpp file and it worked for me (obviously changing the user and password data from the connection string). I am using Linux Red Hat 9.0 with 2.6.8 Kernel. This is what I used to compile: g++ -O3 -c -o check.o check.cpp g++ -o check ppp.o -lmysqlclient_r -lz It worked fine, maybe you should try to compile with debug options and give gdb a try. Cheers, Jose Miguel. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: c program Bus Error (core dumped)
I have a slight variation on that for my Solaris 2.8 machine... g++ -m64 -o check check.cpp -L/usr/local/mysql/lib -L/usr/local/lib/sparcv9/ -lmysqlclient -lsocket -lnsl -lm // this part works fine When running 'check' I get ... check ld.so.1: ./check: fatal: libstdc++.so.5: open failed: No such file or directory Killed ... even though libstdc++.so.5 is symlinked to libstdc++.so.5.0.2 in /usr/local/lib/sparcv9 My apologies for keeping on bothering you!! Regards Andy On Tue, 2005-01-11 at 16:53 +0100, Jose Miguel Pérez wrote: Hi Andy! but I still get the Bus Error message with the following code... int main(char **args) { MYSQL_RES *result; MYSQL_ROW row; MYSQL *connection, mysql; int state; int PORTNUM = 3306; [...] Andy, I have copied and pasted your code into a fresh new check.cpp file and it worked for me (obviously changing the user and password data from the connection string). I am using Linux Red Hat 9.0 with 2.6.8 Kernel. This is what I used to compile: g++ -O3 -c -o check.o check.cpp g++ -o check ppp.o -lmysqlclient_r -lz It worked fine, maybe you should try to compile with debug options and give gdb a try. Cheers, Jose Miguel. -- perl -e print qq^bIG VeRN ! ^^qq^#'#Yv#=D+ ^ This e-mail is private and may be confidential and is for the intended recipient only. If misdirected, please notify us by telephone and confirm that it has been deleted from your system and any copies destroyed. If you are not the intended recipient you are strictly prohibited from using, printing, copying, distributing or disseminating this e-mail or any information contained in it. We use reasonable endeavours to virus scan all e-mails leaving the Company but no warranty is given that this e-mail and any attachments are virus free. You should undertake your own virus checking. The right to monitor e-mail communications through our network is reserved by us. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: c program Bus Error (core dumped)
After compiling with the options (as suggested by Jose Miguel Pérez) g++ -m64 -o check check.cpp -L/usr/local/mysql/lib -L/usr/local/lib/sparcv9 -L/usr/lib -lmysqlclient -lsocket -lnsl -lm ... and getting the subsequent error when running the compiled binary 'check'... ld.so.1: ./check: fatal: libstdc++.so.5: open failed: No such file or directory Killed ... I put /usr/local/lib/sparcv9 in my LD_LIBRARY_PATH and recompiled. I now get ... Everything Cool with the connection Bus Error (core dumped) Sound familiar!! Does anyone have any ideas why I might be seeing this? This is a 64bit kernel Solaris 2.8 Sunfire V120. I'm thinking it may be an architecture thing!! Thanks Andy On Tue, 2005-01-11 at 15:29 +, Andy Ford wrote: I can get something working however. int main(char **args) { MYSQL_RES *result; MYSQL_ROW row; MYSQL *connection, mysql; char *serverInfo=; int state; int PORTNUM = 3306; unsigned long int version; mysql_init(mysql); connection = mysql_real_connect(mysql, localhost, username, password, mydb, PORTNUM, NULL, 0); /* check for a connection error */ if( connection == NULL ) { /* print the error message */ printf(%s\n,mysql_error(mysql)); return 1; } else { printf(%s\n,Everything Cool with the connection); } printf(version = %ul\n, mysql_get_server_version(mysql)); mysql_close(connection); printf(%s\n,Done.); } ... prints out ... Everything Cool with the connection version = 40107l Done. ... but that is as far as I can go until I can fix the Bus Error Regards Andy On Tue, 2005-01-11 at 14:19 +, Andy Ford wrote: Thanks Jose ... but I still get the Bus Error message with the following code... int main(char **args) { MYSQL_RES *result; MYSQL_ROW row; MYSQL *connection, mysql; int state; int PORTNUM = 3306; mysql_init(mysql); connection = mysql_real_connect(mysql, localhost, root, 0sg0sb4Ig, oui, PORTNUM, NULL, 0); if( connection == NULL ) { printf(%s\n,mysql_error(mysql)); return 1; } else { printf(%s\n,Everything Cool with the connection); } state = mysql_query(connection, SELECT sysName from inv_device); result = mysql_store_result(connection); if (result) { printf( Return set: columns=%d, rows=%d \n, mysql_field_count(connection), mysql_num_rows(result)); mysql_free_result(result); } else { printf(%s\n, mysql_error(connection)); return 1; } mysql_close(connection); printf(%s\n,Done.); } Regards Andy On Tue, 2005-01-11 at 14:57 +0100, Jose Miguel Pérez wrote: Hi Andy, state = mysql_query(connection, SELECT * from mytable); *** ^^ if( state ) { printf(mysql_error(connection)); return 1; } else { printf(Everything Cool with the query\n); } // New code, retrieve resultset. result = mysql_store_result(connection); if (result) { printf( Return set: columns=%d, rows=%d \n, mysql_field_count(connection), mysql_num_rows(result)); mysql_free_result(__result); } else { printf(%s\n, mysql_error(connection)); return 1; } // New code - mysql_close(connection); printf(Done.\n); After doing a SELECT statement you should issue a mysql_store_result / mysql_use_result operation to flush the resultset returned (even an empty resultset). In fact, you should flush the resultset stream with every SQL statement that returns data like SELECT, SHOW, DESCRIBE, and the like. See the manual page on mysql_store_result for more information. Once in there, you can follow the directions about section 21.2.3.20 mysql_field_count() about using mysql_field_count to check in you need to flush the resultset. Do not forget to call mysql_free_result to free the memory allocated for the returned resultset. Hope this helps, maybe mysql_close(...) got confused by pending data from the server. One note though, you should NEVER use 'printf(whatever);' use 'printf(%s, whatever);' instead. If it happends to be some % inside whatever you will get coredumps. For instance, see what happends when in your program, mysql_error(connection) returns Please use %d to display integers. (Not a real MySQL error, obviously!! :-) Cheers, Jose Miguel. -- perl -e print qq^bIG VeRN ! ^^qq^#'#Yv#=D+ ^ This e-mail is private and may be confidential and is for the intended recipient only.
Re: c program Bus Error (core dumped)
Hi Andy! After compiling with the options (as suggested by Jose Miguel Pérez) [...] I now get ... Everything Cool with the connection Bus Error (core dumped) Sound familiar!! Sorry Andy but I couldn't help any more. I am not familiar with Solaris, not even with 64 bit machines. The only thing I can think of is you are linking with a 32 bit compiled libmysql library, but... I don't know. Cheers, Jose Miguel. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
SOLVED (at last) Re: c program Bus Error (core dumped)
It was mentioned by the two people cc'd in this mail that the mixture of a 64bit mysqld and libraries with a 32-bit gcc/g++ was not a good idea. How right they were!! I have just installed the latest 4.1.8 32-bit Solaris 2.8 binary and it all works wonderfully. Thanks for all of your help Andy On Tue, 2005-01-11 at 16:10 +, Andy Ford wrote: I have a slight variation on that for my Solaris 2.8 machine... g++ -m64 -o check check.cpp -L/usr/local/mysql/lib -L/usr/local/lib/sparcv9/ -lmysqlclient -lsocket -lnsl -lm // this part works fine When running 'check' I get ... check ld.so.1: ./check: fatal: libstdc++.so.5: open failed: No such file or directory Killed ... even though libstdc++.so.5 is symlinked to libstdc++.so.5.0.2 in /usr/local/lib/sparcv9 My apologies for keeping on bothering you!! Regards Andy On Tue, 2005-01-11 at 16:53 +0100, Jose Miguel Pérez wrote: Hi Andy! but I still get the Bus Error message with the following code... int main(char **args) { MYSQL_RES *result; MYSQL_ROW row; MYSQL *connection, mysql; int state; int PORTNUM = 3306; [...] Andy, I have copied and pasted your code into a fresh new check.cpp file and it worked for me (obviously changing the user and password data from the connection string). I am using Linux Red Hat 9.0 with 2.6.8 Kernel. This is what I used to compile: g++ -O3 -c -o check.o check.cpp g++ -o check ppp.o -lmysqlclient_r -lz It worked fine, maybe you should try to compile with debug options and give gdb a try. Cheers, Jose Miguel. -- perl -e print qq^bIG VeRN ! ^^qq^#'#Yv#=D+ ^ This e-mail is private and may be confidential and is for the intended recipient only. If misdirected, please notify us by telephone and confirm that it has been deleted from your system and any copies destroyed. If you are not the intended recipient you are strictly prohibited from using, printing, copying, distributing or disseminating this e-mail or any information contained in it. We use reasonable endeavours to virus scan all e-mails leaving the Company but no warranty is given that this e-mail and any attachments are virus free. You should undertake your own virus checking. The right to monitor e-mail communications through our network is reserved by us. -- perl -e print qq^bIG VeRN ! ^^qq^#'#Yv#=D+ ^ -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]