cercig
June 6th, 2014, 02:02 PM
Hi,
I need an urgent answer. I am trying to write a C code with embedded MySQL server and client options. The compiler is gcc.I added the location of the header file manually in the code; like: #include "/usr/include/mysql/mysql.h"
I have the necessary library installed: libmysqld-dev which includes MySQL embedded development libraries.
When I compile my code very simply like: "gcc test.c" I get errors like this:
prov.c:(.text+0x1b): undefined reference to `mysql_server_init'
prov.c:(.text+0x25): undefined reference to `mysql_init'
prov.c: (.text+0x45): undefined reference to `mysql_options'
prov.c: (.text+0x5e): undefined reference to `mysql_options'
prov.c: (.text+0x99): undefined reference to `mysql_real_connect'
prov.c: (.text+0xad): undefined reference to `mysql_query'
prov.c: (.text+0xbc): undefined reference to `mysql_store_result'
prov.c: (.text+0x101): undefined reference to `mysql_fetch_row'
prov.c: (.text+0x123): undefined reference to `mysql_free_result'
prov.c: (.text+0x132): undefined reference to `mysql_close'
prov.c: (.text+0x137): undefined reference to `mysql_server_end'
My code is below:
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "/usr/include/mysql/mysql.h"
MYSQL *mysql;
MYSQL_RES *results;
MYSQL_ROW record;
static char *server_options[] = { "prov", "--defaults-file=my.cnf" };
int num_elements = sizeof(server_options)/ sizeof(char *);
static char *server_groups[] = { "libmysqld_server", "libmysqld_client" };
int main(void)
{
mysql_server_init(num_elements, server_options, server_groups);
mysql = mysql_init(NULL);
mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "libmysqld_client");
mysql_options(mysql, MYSQL_OPT_USE_EMBEDDED_CONNECTION, NULL);
mysql_real_connect(mysql, NULL,NULL,NULL, "data", 0,NULL,0);
mysql_query(mysql, "SELECT data_id, from the data series");
results = mysql_store_result(mysql);
while((record = mysql_fetch_row(results))) {
printf("%s - %s \n", record[0], record[1]);
}
mysql_free_result(results);
mysql_close(mysql);
mysql_server_end();
return 0;
}
I need an urgent answer. I am trying to write a C code with embedded MySQL server and client options. The compiler is gcc.I added the location of the header file manually in the code; like: #include "/usr/include/mysql/mysql.h"
I have the necessary library installed: libmysqld-dev which includes MySQL embedded development libraries.
When I compile my code very simply like: "gcc test.c" I get errors like this:
prov.c:(.text+0x1b): undefined reference to `mysql_server_init'
prov.c:(.text+0x25): undefined reference to `mysql_init'
prov.c: (.text+0x45): undefined reference to `mysql_options'
prov.c: (.text+0x5e): undefined reference to `mysql_options'
prov.c: (.text+0x99): undefined reference to `mysql_real_connect'
prov.c: (.text+0xad): undefined reference to `mysql_query'
prov.c: (.text+0xbc): undefined reference to `mysql_store_result'
prov.c: (.text+0x101): undefined reference to `mysql_fetch_row'
prov.c: (.text+0x123): undefined reference to `mysql_free_result'
prov.c: (.text+0x132): undefined reference to `mysql_close'
prov.c: (.text+0x137): undefined reference to `mysql_server_end'
My code is below:
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "/usr/include/mysql/mysql.h"
MYSQL *mysql;
MYSQL_RES *results;
MYSQL_ROW record;
static char *server_options[] = { "prov", "--defaults-file=my.cnf" };
int num_elements = sizeof(server_options)/ sizeof(char *);
static char *server_groups[] = { "libmysqld_server", "libmysqld_client" };
int main(void)
{
mysql_server_init(num_elements, server_options, server_groups);
mysql = mysql_init(NULL);
mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "libmysqld_client");
mysql_options(mysql, MYSQL_OPT_USE_EMBEDDED_CONNECTION, NULL);
mysql_real_connect(mysql, NULL,NULL,NULL, "data", 0,NULL,0);
mysql_query(mysql, "SELECT data_id, from the data series");
results = mysql_store_result(mysql);
while((record = mysql_fetch_row(results))) {
printf("%s - %s \n", record[0], record[1]);
}
mysql_free_result(results);
mysql_close(mysql);
mysql_server_end();
return 0;
}