You are not logged in.
#include <mysql/mysql.h>
#include <stdio.h>
int main()
{
MYSQL mysql;
mysql_init(&mysql);
mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"your_prog_name");
if (!mysql_real_connect(&mysql,"host","user","passwd","database",0,NULL,0))
{
fprintf(stderr, "Failed to connect to database: Error: %sn",
mysql_error(&mysql));
}
return 0;
}
This code are from mysql manual.
When I try to compile it, I get the following message:
/tmp/ccojokYy.o(.text+0x29): In function `main':
: undefined reference to `mysql_init'
/tmp/ccojokYy.o(.text+0x47): In function `main':
: undefined reference to `mysql_options'
/tmp/ccojokYy.o(.text+0x8d): In function `main':
: undefined reference to `mysql_real_connect'
/tmp/ccojokYy.o(.text+0xa4): In function `main':
: undefined reference to `mysql_error'
collect2: ld returned 1 exit status
Offline
What command line did you use to compile?
Did you linked with the mysql library?
Offline
gcc source_file.c -lmysqlclient
Offline
Oh, it worked. Thank you!
Offline