Вроде нарыл что да как, но проблема, всё равно не получается, может гуру си пояснят, что да как. Я относительно не давно начал программить на си.
Вот программа:
#include <mysql/mysql.h>
#include <stdio.h>
void main(void)
{
MYSQL *mysql;
MYSQL_RES *res;
MYSQL_ROW row;
char *query;
int t,r;
mysql_init(mysql);
if (!mysql_real_connect(mysql,"localhost","root",
"","cybeast",0,NULL,0))
{
printf( "Error connecting to database: %s\n",mysql_error(mysql));
}
else printf("Connected...\n");
query="select * from test";
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);
}
---
Всё как в мануалах...
А вот что выдаётся при "компилинге":
root@ch00r:~/mysql# gcc mysql2.c -o mysql
mysql2.c: In function `main':
mysql2.c:5: warning: return type of `main' is not `int'
/tmp/ccoxWTgs.o(.text+0x17): In function `main':
: undefined reference to `mysql_init'
/tmp/ccoxWTgs.o(.text+0x3c): In function `main':
: undefined reference to `mysql_real_connect'
/tmp/ccoxWTgs.o(.text+0x51): In function `main':
: undefined reference to `mysql_error'
/tmp/ccoxWTgs.o(.text+0x98): In function `main':
: undefined reference to `mysql_real_query'
/tmp/ccoxWTgs.o(.text+0xb2): In function `main':
: undefined reference to `mysql_error'
/tmp/ccoxWTgs.o(.text+0xe0): In function `main':
: undefined reference to `mysql_use_result'
/tmp/ccoxWTgs.o(.text+0xf8): In function `main':
: undefined reference to `mysql_field_count'
/tmp/ccoxWTgs.o(.text+0x10d): In function `main':
: undefined reference to `mysql_fetch_row'
/tmp/ccoxWTgs.o(.text+0x125): In function `main':
: undefined reference to `mysql_num_fields'
/tmp/ccoxWTgs.o(.text+0x178): In function `main':
: undefined reference to `mysql_close'
collect2: ld returned 1 exit status
---
Странно почему ld не хочит линковать. А также строчка "mysql2.c:5: warning: return type of `main' is not `int'"
При чём тут это? Если я чётко указал "void main(void)"
ПОМОГИТЕ! очень надо :)
За ранее спасибо.
|