Hello all,
I'm trying to write an application which uses the MySQL embedded
server. I've looked through the documentation
(http://www.mysql.com/doc/en/libmysqld.html), and I've tried to compile
their simple example program (see [makefile] and [test_libmysqld.c]
attached), but I keep getting a whole horde of linker errors akin to the
following:
++++++++++++++++++++++++++++++++++++++++
[EMAIL PROTECTED] mysql $ make
gcc -g -W -Wall -I/usr/include/mysql -D_THREAD_SAFE -D_REENTRANT
-static test_libmysqld.c -L/usr/lib/mysql -lmysqld -lz -lm -lcrypt
-lpthread -o test_libmysqld
/usr/lib/mysql/libmysqld.a(lib_sql.o)(.text+0x2186): In function
`handle_connections_sockets':
: undefined reference to `request_init'
/usr/lib/mysql/libmysqld.a(lib_sql.o)(.text+0x218e): In function
`handle_connections_sockets':
: undefined reference to `sock_host'
/usr/lib/mysql/libmysqld.a(lib_sql.o)(.text+0x2196): In function
`handle_connections_sockets':
: undefined reference to `hosts_access'
/usr/lib/mysql/libmysqld.a(lib_sql.o)(.text+0x21a6): In function
`handle_connections_sockets':
: undefined reference to `eval_client'
/usr/lib/mysql/libmysqld.a(field.o)(.gnu.linkonce.d._ZTV9Field_str+0x10): undefined
reference to `__cxa_pure_virtual'
/usr/lib/mysql/libmysqld.a(field.o)(.gnu.linkonce.d._ZTV9Field_str+0x14): undefined
reference to `__cxa_pure_virtual'
/usr/lib/mysql/libmysqld.a(field.o)(.gnu.linkonce.d._ZTV9Field_str+0x18): undefined
reference to `__cxa_pure_virtual'
/usr/lib/mysql/libmysqld.a(field.o)(.gnu.linkonce.d._ZTV9Field_str+0x20): undefined
reference to `__cxa_pure_virtual'
/usr/lib/mysql/libmysqld.a(field.o)(.gnu.linkonce.d._ZTV9Field_str+0x24): undefined
reference to `__cxa_pure_virtual'
/usr/lib/mysql/libmysqld.a(field.o)(.gnu.linkonce.d._ZTV9Field_str+0x28): more
undefined references to `__cxa_pure_virtual' follow
/usr/lib/mysql/libmysqld.a(hostname.o)(.text+0xd5): In function
`hostname_cache_init()':
: undefined reference to `operator new(unsigned)'
/usr/lib/mysql/libmysqld.a(hostname.o)(.text+0x22b): In function
`hostname_cache_free()':
: undefined reference to `operator delete(void*)'
/usr/lib/mysql/libmysqld.a(item.o)(.gnu.linkonce.d._ZTV9Item_buff+0x8):
undefined reference to `__cxa_pure_virtual'
/usr/lib/mysql/libmysqld.a(item.o)(.gnu.linkonce.d._ZTV17Item_result_field+0x2c):
undefined reference to `__cxa_pure_virtual'
/usr/lib/mysql/libmysqld.a(item.o)(.gnu.linkonce.d._ZTV17Item_result_field+0x30):
undefined reference to `__cxa_pure_virtual'
/usr/lib/mysql/libmysqld.a(item.o)(.gnu.linkonce.d._ZTV17Item_result_field+0x34):
undefined reference to `__cxa_pure_virtual'
/usr/lib/mysql/libmysqld.a(item.o)(.gnu.linkonce.d._ZTV17Item_result_field+0x38):
undefined reference to `__cxa_pure_virtual'
/usr/lib/mysql/libmysqld.a(item.o)(.gnu.linkonce.d._ZTV17Item_result_field+0x3c): more
undefined references to `__cxa_pure_virtual' follow
/usr/lib/mysql/libmysqld.a(item_func.o)(.text+0x2f20): In function
`item_user_lock_release(ULL*)':
: undefined reference to `operator delete(void*)'
/usr/lib/mysql/libmysqld.a(item_func.o)(.text+0x33a7): In function
`Item_func_get_lock::val_int()':
: undefined reference to `operator delete(void*)'
/usr/lib/mysql/libmysqld.a(item_func.o)(.text+0x3472): In function
`Item_func_get_lock::val_int()':
: undefined reference to `operator new(unsigned)'
/usr/lib/mysql/libmysqld.a(item_func.o)(.text+0x34d2): In function
`Item_func_get_lock::val_int()':
: undefined reference to `operator delete(void*)'
/usr/lib/mysql/libmysqld.a(item_func.o)(.gnu.linkonce.d._ZTV17Item_func_integer+0x34):
undefined reference to `__cxa_pure_virtual'
/usr/lib/mysql/libmysqld.a(item_func.o)(.gnu.linkonce.d._ZTV13Item_dec_func+0x30):
undefined reference to `__cxa_pure_virtual'
/usr/lib/mysql/libmysqld.a(item_func.o)(.gnu.linkonce.d._ZTV13Item_int_func+0x34):
undefined reference to `__cxa_pure_virtual'
/usr/lib/mysql/libmysqld.a(item_func.o)(.gnu.linkonce.d._ZTV11Item_num_op+0x30):
undefined reference to `__cxa_pure_virtual'
/usr/lib/mysql/libmysqld.a(item_func.o)(.gnu.linkonce.d._ZTV11Item_num_op+0x34):
undefined reference to `__cxa_pure_virtual'
...
+++++++++++++++++++++++++++++++++++++++++++
There's a lot more than that, but I imagine you get the idea. It looks
like a linker error, but I've done everything that I can think of to
solve the problem, including remaking libmysqld.a, the embedded database
engine. Has anyone encountered this before, or do you have any
suggestions?
Any and all help would be appreciated.
Thanks,
Hyrum
--
Need an Open Source Genealogy tool? Help write one!
http://sourceforge.net/projects/openancestry
#This assumes the MySQL software is installed in /usr/local/mysql
inc := /usr/include/mysql
lib := /usr/lib/mysql
# If you have not installed the MySQL software yet, try this instead
#inc := $(HOME)/mysql-4.0/include
#lib := $(HOME)/mysql-4.0/libmysqld
CC := gcc
CPPFLAGS := -I$(inc) -D_THREAD_SAFE -D_REENTRANT
CFLAGS := -g -W -Wall
LDFLAGS := -static
# You can change -lmysqld to -lmysqlclient to use the
# client/server library
LDLIBS = -L$(lib) -lmysqld -lz -lm -lcrypt
ifneq (,$(shell grep FreeBSD /COPYRIGHT 2>/dev/null))
# FreeBSD
LDFLAGS += -pthread
else
# Assume Linux
LDLIBS += -lpthread
endif
# This works for simple one-file test programs
sources := $(wildcard *.c)
objects := $(patsubst %c,%o,$(sources))
targets := $(basename $(sources))
all: $(targets)
clean:
rm -f $(targets) $(objects) *.core
/*asimple example client, using the embedded MySQL server library
*/
#include <mysql.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
MYSQL *db_connect(const char *dbname);
void db_disconnect(MYSQL *db);
void db_do_query(MYSQL *db, const char *query);
const char *server_groups[] = {
"test_libmysqld_SERVER", "embedded", "server", NULL
};
int
main(int argc, char **argv)
{
MYSQL *one, *two;
/* mysql_server_init() must be called before any other mysql
* functions.
*
* You can use mysql_server_init(0, NULL, NULL), and it will
* initialise the server using groups = {
* "server", "embedded", NULL
* }.
*
* In your $HOME/.my.cnf file, you probably want to put:
[test_libmysqld_SERVER]
language = /path/to/source/of/mysql/sql/share/english
* You could, of course, modify argc and argv before passing
* them to this function. Or you could create new ones in any
* way you like. But all of the arguments in argv (except for
* argv[0], which is the program name) should be valid options
* for the MySQL server.
*
* If you link this client against the normal mysqlclient
* library, this function is just a stub that does nothing.
*/
mysql_server_init(argc, argv, (char **)server_groups);
one = db_connect("test");
two = db_connect(NULL);
db_do_query(one, "SHOW TABLE STATUS");
db_do_query(two, "SHOW DATABASES");
mysql_close(two);
mysql_close(one);
/* This must be called after all other mysql functions */
mysql_server_end();
exit(EXIT_SUCCESS);
}
static void
die(MYSQL *db, char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
(void)putc('\n', stderr);
if (db)
db_disconnect(db);
exit(EXIT_FAILURE);
}
MYSQL *
db_connect(const char *dbname)
{
MYSQL *db = mysql_init(NULL);
if (!db)
die(db, "mysql_init failed: no memory");
/*
* Notice that the client and server use separate group names.
* This is critical, because the server will not accept the
* client's options, and vice versa.
*/
mysql_options(db, MYSQL_READ_DEFAULT_GROUP, "test_libmysqld_CLIENT");
if (!mysql_real_connect(db, NULL, NULL, NULL, dbname, 0, NULL, 0))
die(db, "mysql_real_connect failed: %s", mysql_error(db));
return db;
}
void
db_disconnect(MYSQL *db)
{
mysql_close(db);
}
void
db_do_query(MYSQL *db, const char *query)
{
MYSQL_RES *res;
if (mysql_query(db, query) != 0)
goto err;
if (mysql_field_count(db) > 0)
{
MYSQL_ROW row, end_row;
int num_fields;
if (!(res = mysql_store_result(db)))
goto err;
num_fields = mysql_num_fields(res);
while ((row = mysql_fetch_row(res)))
{
(void)fputs(">> ", stdout);
for (end_row = row + num_fields; row < end_row; ++row)
(void)printf("%s\t", row ? (char*)*row : "NULL");
(void)fputc('\n', stdout);
}
(void)fputc('\n', stdout);
}
else
(void)printf("Affected rows: %lld\n", mysql_affected_rows(db));
mysql_free_result(res);
return;
err:
die(db, "db_do_query failed: %s [%s]", mysql_error(db), query);
}
____________________
BYU Unix Users Group
http://uug.byu.edu/
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list