MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 9th, 2000, 12:46 PM
adriana adriana is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 4 adriana User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Does any one know how to fix this compiling problem?

I´m new using MySQL so I took this source code to make some tests:

#include <sys/time.h>
#include <stdio.h>
#include <mysql.h>

int main (char **args)
{
MYSQL_RES *result;
MYSQL_ROW row;
MYSQL *connection, mysql;
int state;

/* connect to database */
mysql_init(&mysql);
connection =
mysql_real_connect(&mysql,"localhost","user","password","database",
0,0,0);

/* check for connection error */
if (connection == NULL)
{
/* print error message */
printf(mysql_error(&mysql));
return 1;
}
state = mysql_query(connection, "SELECT x, y FROM tablename");
if (state != 0)
{
printf(mysql_error(connection));
return 1;
}

/* must call mysql_store_result() before we can issue any other
* query calls
*/
result = mysql_store_result(connection);
printf("Rows: %dn", mysql_num_rows(result));

/* process each row in result set */
while ((row = mysql_fetch_row(result)) != NULL)
{
printf("id: %s, val: %sn",
(row[1] ? row[1] : "NULL"),
(row[0] ? row[0] : "NULL"));
}

/* free the result set */
mysql_free_result(result);

/* close the connection */
mysql_close(connection);
printf("Done.n");
}


When I compiling the error list are:

Undefined first referenced
symbol in file
mysql_close test.o
mysql_free_result test.o
mysql_fetch_row test.o
mysql_real_connect test.o
mysql_store_result test.o
mysql_query test.o
mysql_init test.o
ld: fatal: Symbol referencing errors. No output written to test


The command is:

$ /opt/SUNWspro/bin/cc -o test test.c -I/usr/local/mysql/include -L/usr/lib


Does any one know how can I fix it?

Please help,
Adriana


***********************

Finally I got the solution with this example:

/***************************************************/
/*
connect.c
*/
/* a simple connection test
script */
/* Mysql C
API
*/
/***************************************************/

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

#define def_hostname "localhost"
#define def_username "your username in these quotes"
#define def_password "your password in these quotes"
#define def_dbName "your database name in these quotes"

MYSQL *conn;

int main(int argc, char *argv[])
{
conn=mysql_init(NULL);
if(conn==NULL)
{
fprintf(stderr, "mysql_init() failedn");
return 1;
}
if(mysql_real_connect(conn, def_hostname, def_username, def_password,
def_dbName, 0, NULL, 0)==NULL)
{
fprintf(stderr, "mysql_real_connect() failed:nError %u
(%s)n", mysql_errno(conn), mysql_error(conn));
return 1;
}
else
{
fprintf(stdout, "Connection to mysql server establishedn");

}
mysql_close(conn);
return 0;
}


And the compiling command:

cc -c -I/usr/local/mysql/include connect.c}
cc -o connect connect.o -L/usr/local/mysql/lib -lmysqlclient -lxnet -lm

Regards,
Adriana

PS: Thank you Kyuzo for the hint

[This message has been edited by adriana (edited June 13, 2000).]

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Compiling problems!!! Help!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT