Helpful Information
 
 
Category: Databases
C/C++ w/MySQL [linux]

Hopefully this is just a really silly question:

I can't figure out where the MySQL library is at!

I'm using Linux RH 5.2 & MySQL installed by using the source RPM and doing rpm --rebuild [mysql.rpm]. I've done some quick tests and verified mysqld is working ok.

I found the include files:

/var/tmp/mysql/usr/include/mysql/mysql.h

The test program I wrote:

#include <stdio.h>
#include <sys/time.h>
#include </var/tmp/mysql/usr/include/mysql/mysql.h>

void main()
{
MYSQL_RES *result;
MYSQL_ROW row;
MYSQL *connection, mysql;
int state;

mysql_init(&mysql);

printf("Done.");
} // end void main()

I compile using g++:
/tmp/cca057881.o: In function `main':
/tmp/cca057881.o(.text+0x11): undefined reference to `mysql_init'
collect2: ld returned 1 exit status

If I compile under gcc I get the same error. I beleive this is because g++/gcc don't know where the libraries are at (and neither do I!)

Ideas?

Astro

Try changing the third include directive back to #include <mysql.h> and use the -I, -L and -lmysqlclient switches when compiling and linking

gcc -c -I/var/tmp/mysql/usr/include/mysql program.c

then

gcc -o program program.o -L/var/tmp/mysql/usr/lib/mysql -lmysqlclient

..or wherever the header files and client library are located










privacy (GDPR)