Computing.Net > Forums > Database > c program to access mysql - failed

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

c program to access mysql - failed

Reply to Message Icon

Name: pnbalaji
Date: November 25, 2008 at 15:04:02 Pacific
OS: AIX 5.3
CPU/Ram: 8GB RAM
Product: IBM
Comment:

Hi,

I coded a c program (mysqlc.c) to access the mysql database and dump the results. The program is given below.

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

int main(void) {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
/* Change me */
char *server = "leuscs03";
char *user = "guest";
char *password = "setnew1";
char *database = "mysql";

conn = mysql_init(NULL);

/* Connect to database */
if (!mysql_real_connect(conn, server,
user, password, database, 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}

/* send SQL query */
if (mysql_query(conn, "show tables")) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}

res = mysql_use_result(conn);

/* output table name */
printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
printf("%s \n", row[0]);

/* close connection */
mysql_free_result(res);
mysql_close(conn);

return 0;
}
=============================================

I am using the following command to compile the program mysqlc.c.

=============================================
/usr/bin/gcc -o mysqlc.exe -I/usr/local/bin/mysql/include -g -DUNIV_AIX mysqlc.c -L/usr/local/bin/mysql/lib -lmysqlclient -lz -lrt -lnsl_r
=============================================

mysql is installed under /usr/local/bin instead of /usr/local in our box.

During compilation, I am getting the following error messages.
=============================================
mysqlc.c: In function 'main':
mysqlc.c:25: warning: incompatible implicit declaration of built-in function 'exit'
mysqlc.c:31: warning: incompatible implicit declaration of built-in function 'exit'
ld: 0711-317 ERROR: Undefined symbol: .mysql_init
ld: 0711-317 ERROR: Undefined symbol: .mysql_real_connect
ld: 0711-317 ERROR: Undefined symbol: .mysql_error
ld: 0711-317 ERROR: Undefined symbol: .mysql_query
ld: 0711-317 ERROR: Undefined symbol: .mysql_use_result
ld: 0711-317 ERROR: Undefined symbol: .mysql_fetch_row
ld: 0711-317 ERROR: Undefined symbol: .mysql_free_result
ld: 0711-317 ERROR: Undefined symbol: .mysql_close
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information
collect2: ld returned 8 exit status
=============================================

I did some reading and it looks like all the above methods are supposed to be in the libmysqlclient.a and I could see that this file is available under /usr/local/bin/mysql/lib and I am passing this to the linker using the -L option.

Can some one help me how to resolve this issue?

Thanks,
Balaji.



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Database Forum Home


Sponsored links

Ads by Google


Results for: c program to access mysql - failed

using administrator to reset psswrd www.computing.net/answers/dbase/using-administrator-to-reset-psswrd/432.html

How to access local database? www.computing.net/answers/dbase/how-to-access-local-database/273.html

converting excel worksheets to access tables www.computing.net/answers/dbase/converting-excel-worksheets-to-access-tables/651.html