Linking a MySQL client
From: Graham Banks (none_at_given)
Date: 07/25/04
- Next message: Larry I Smith: "Re: Linking a MySQL client"
- Previous message: Jens.Toerring_at_physik.fu-berlin.de: "Re: encrypt and decrypt using encrypt(char block[64], int edflag)"
- Next in thread: Larry I Smith: "Re: Linking a MySQL client"
- Reply: Larry I Smith: "Re: Linking a MySQL client"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 25 Jul 2004 15:37:48 +0100
I'm trying to add MySQL client functionality to a project but I'm having
problems linking. I've created a very simple test project to see if I can
get that to build and the same problem occurs. The problem is undefined
references. Here is the output of make: (btw, I deliberately threw in an
undefined function, 'unknown', to show that all the functions are properly
prototyped by the include files)
>>>>
g++ -g -I/usr/include/mysql -mcpu=i486 -fno-strength-reduce -pedantic -Wimp
licit-function-declaration -c -o db.o db.cc
db.cc:12: warning: return type for `main' changed to `int'
cc -g -I/usr/include/mysql -mcpu=i486 -fno-strength-reduce -pedantic -Wimpl
icit-function-declaration -c -o mysqlif.o mysqlif.c
mysqlif.c: In function `mysqlifTerminate':
mysqlif.c:68: warning: implicit declaration of function `unknown'
cc -lz -lcrypt -lnsl -lm -lc -lnss_files -lnss_dns -lresolv -lc -lnss_files
-lnss_dns -lresolv -L/usr/lib/mysql -lmysqlclient db.o mysqlif.o -o db
mysqlif.o: In function `mysqlifInit':
/home/graham/code/Noddys/mysql/mysqlif.c:21: undefined reference to
`mysql_init'
/home/graham/code/Noddys/mysql/mysqlif.c:24: undefined reference to
`mysql_real_connect'
/home/graham/code/Noddys/mysql/mysqlif.c:25: undefined reference to
`mysql_close'
mysqlif.o: In function `mysqlifQuery':
/home/graham/code/Noddys/mysql/mysqlif.c:35: undefined reference to
`mysql_query'
mysqlif.o: In function `mysqlifStoreResult':
/home/graham/code/Noddys/mysql/mysqlif.c:41: undefined reference to
`mysql_store_result'
mysqlif.o: In function `mysqlifNumFields':
/home/graham/code/Noddys/mysql/mysqlif.c:46: undefined reference to
`mysql_num_fields'
mysqlif.o: In function `mysqlifFreeResult':
/home/graham/code/Noddys/mysql/mysqlif.c:51: undefined reference to
`mysql_free_result'
mysqlif.o: In function `mysqlifFetchRow':
/home/graham/code/Noddys/mysql/mysqlif.c:57: undefined reference to
`mysql_fetch_row'
mysqlif.o: In function `mysqlifTerminate':
/home/graham/code/Noddys/mysql/mysqlif.c:67: undefined reference to
`mysql_close'
/home/graham/code/Noddys/mysql/mysqlif.c:68: undefined reference to
`unknown'
collect2: ld returned 1 exit status
make: *** [db] Error 1
<<<<
I've searched for answers to the problem on the Internet and most of the
answers are about the absence of "-L/usr/lib/mysql" and "-lmysqlclient".
However, these flags are present in LDFLAGS, /usr/lib/mysql is where my
mysql libraries are kept, and
libmysqlclient.a is there. Here's a listing of /usr/lib/mysql:
>>>>
-rw-r--r-- 1 root root 10998 May 16 03:00 libdbug.a
-rw-r--r-- 1 root root 35614 May 16 03:00 libheap.a
-rw-r--r-- 1 root root 15254 May 16 03:00 libmerge.a
-rw-r--r-- 1 root root 263558 May 16 03:00 libmyisam.a
-rw-r--r-- 1 root root 26438 May 16 03:00 libmyisammrg.a
-rw-r--r-- 1 root root 310390 May 16 03:00 libmysqlclient.a
-rwxr-xr-x 1 root root 849 May 16 03:00 libmysqlclient.la
-rw-r--r-- 1 root root 318494 May 16 03:00 libmysqlclient_r.a
-rwxr-xr-x 1 root root 875 May 16 03:00 libmysqlclient_r.la
-rw-r--r-- 1 root root 113818 May 16 03:00 libmystrings.a
-rw-r--r-- 1 root root 243780 May 16 03:00 libmysys.a
-rw-r--r-- 1 root root 101332 May 16 03:00 libnisam.a
-rw-r--r-- 1 root root 6014 May 16 03:00 libvio.a
-rw-r--r-- 1 root root 410526 May 16 03:00 mysqld.sym
<<<<
Now, there's no libmysqlclient.so anywhere on my system, but I shouldn't
need
it, should I? The library file in /usr/lib/mysql is for static linking, and
as far as I know, the linker will do that because libmysqlclient.a is there.
Or is there something I should be doing to explicitly make it statically
link. I've tried putting a -static flag in the LDFLAGS, but that breaks the
linking of other libraries.
I did come across some advice that directed the reader to the article
http://www.hk8.org/old_web/linux/sql/ch13_01.htm. This says:
>>>>
To compile this program using the GNU C compiler, use the command line:
gcc -L/usr/local/mysql/lib -I/usr/local/mysql/include -o select
select.c\ -lmysql -lnsl -lsocket
<<<<
I tried this but -lmysql was reported not found. I can't find libmysql .a
anywhere on my system.
The mysql server and standard client are both properly installed on my
system - I've been able to create and populate a database using the "mysql"
program.
I installed the server, client and development environment from these RPMs
files:
MySQL-client-4.0.20-0.i386.rpm
MySQL-devel-4.0.20-0.i386.rpm
MySQL-server-4.0.20-0.i386.rpm.
Here's my makefile:
>>>>
CPPFLAGS=-g -I/usr/include/mysql -mcpu=i486 -fno-strength-reduce -pedantic -
Wimplicit-function-declaration
LDFLAGS= -lz -lcrypt -lnsl -lm -lc -lnss_files -lnss_dns -lresolv -lc -lnss_
files -lnss_dns -lresolv -L/usr/lib/mysql -lmysqlclient
db: db.o mysqlif.o
db.o: db.cc
mysqlif.o: mysqlif.c
<<<<
And here's mysqlif.c:
>>>>
/*
File: mysqlif.cc
Interface to mysql library */
#include <my_global.h>
#include <my_sys.h>
#include <m_string.h>
#include <mysql.h>
#include <mysql_embed.h>
#include <errmsg.h>
#include <my_getopt.h>
#include "mysqlif.h"
MYSQL *mysql;
MYSQL_RES *res;
MYSQL_ROW row;
int mysqlifInit(void)
{
if (!(mysql = mysql_init(NULL)))
return DBERROR_OUTOFMEMORY;
if
(!(mysql_real_connect(mysql,NULL,"root","hawkwind53","dbGizzy",0,NULL,0))){
mysql_close(mysql);
return DBERROR_CANNOTCONNECT;
}
return DBERROR_OK;
}
//Returns error code ( 0 if OK)
int mysqlifQuery(char *szQuery)
{
return mysql_query(mysql, szQuery);
}
//Returns non-zero if successful
int mysqlifStoreResult(void)
{
return (res = mysql_store_result(mysql)) != NULL;
}
int mysqlifNumFields(void)
{
return mysql_num_fields(res);
}
void mysqlifFreeResult(void)
{
mysql_free_result(res);
}
//Returns non-zero if another row is fetched
int mysqlifFetchRow(void)
{
return (row = mysql_fetch_row(res)) != NULL;
}
char *mysqlifGetValue(int index)
{
return row[index];
}
void mysqlifTerminate()
{
mysql_close(mysql);
unknown();
}
<<<<
Anyone know why I get the linker errors?
TIA,
Graham
- Next message: Larry I Smith: "Re: Linking a MySQL client"
- Previous message: Jens.Toerring_at_physik.fu-berlin.de: "Re: encrypt and decrypt using encrypt(char block[64], int edflag)"
- Next in thread: Larry I Smith: "Re: Linking a MySQL client"
- Reply: Larry I Smith: "Re: Linking a MySQL client"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|