|
After reading some old posts, but still can't get it, always prompt:
undefined reference to '_mysql_init'
undefined reference to '_mysql_real_connection'
undefined reference to '_mysql_error'
undefined reference to '_mysql_real_query'
...
and many more
The environment I use is:
WINDOWS XP SP2
cygwin
gcc3.4.4
MYSQL is Windows version 5.0
Works fine with JAVA.
My compilation is:
gcc -o main.exe main.c -I / usr / include / mysql -lmysqlclient
I have COPY the include file under mysql to / usr / include / mysql
mysqlclient.lib under lib / opt is also COPY to / usr / lib.
Please give me some advice. Thank you very much!
Here is the source code
The source code is from another post of COPY
#include <mysql / mysql.h>
#include <stdio.h>
int main () {
MYSQL * mysql;
MYSQL_RES * res;
MYSQL_ROW row;
char * query;
int t, r;
mysql_init (mysql);
if (! mysql_real_connect (mysql, "localhost", "root",
"loveyou", "spider", 0, NULL, 0))
{
printf ("Error connecting to database:% s\n", mysql_error (mysql));
}
else printf ("Connected ...\n");
query = "select * from spider_work_unsite";
t = mysql_real_query (mysql, query, (unsigned int) strlen (query));
if (t)
{
printf ("Error making query:% s\n",
mysql_error (mysql));
}
else printf ("Query made ...\n");
res = mysql_use_result (mysql);
for (r = 0; r <= mysql_field_count (mysql); r ++) {
row = mysql_fetch_row (res);
if (row <0) break;
for (t = 0; t <mysql_num_fields (res); t ++) {
printf ("% s", row [t]);
}
printf ("\n");
}
mysql_close (mysql);
} |
|