linking to mysql in C

linking to mysql in C

am 08.01.2011 06:06:24 von Delan Azabani

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all,

This is a novice problem I'm having with compiling a C CGI program with
MySQL on my Gentoo box.

I have a simple source so far:

* cbook-main.c: http://pastebin.com/vnT6j1z2
* cbook-main.h: http://pastebin.com/4BnyWs27
* Makefile: http://pastebin.com/m973gbjG

When compiling I receive undefined reference errors:

delan@delan2 ~/cbook $ make
make cbook-main
make[1]: Entering directory `/home/delan/cbook'
cc -g `pkg-config --cflags libconfuse glib-2.0` `mysql_config --cflags`
- -c cbook-main.c
make[1]: Leaving directory `/home/delan/cbook'
cc `pkg-config --libs libconfuse glib-2.0` `mysql_config --libs` -o
cbook.cgi cbook-main.o
cbook-main.o: In function `myerror':
/home/delan/cbook/cbook-main.c:61: undefined reference to `mysql_error'
/home/delan/cbook/cbook-main.c:61: undefined reference to `mysql_errno'
cbook-main.o: In function `myescape':
/home/delan/cbook/cbook-main.c:67: undefined reference to
`mysql_real_escape_string'
cbook-main.o: In function `myquery':
/home/delan/cbook/cbook-main.c:85: undefined reference to `mysql_query'
cbook-main.o: In function `createDatabase':
/home/delan/cbook/cbook-main.c:90: undefined reference to `mysql_select_db'
cbook-main.o: In function `pageHome':
/home/delan/cbook/cbook-main.c:144: undefined reference to
`mysql_store_result'
/home/delan/cbook/cbook-main.c:146: undefined reference to `mysql_fetch_row'
/home/delan/cbook/cbook-main.c:160: undefined reference to
`mysql_free_result'
cbook-main.o: In function `pageSessions':
/home/delan/cbook/cbook-main.c:181: undefined reference to
`mysql_store_result'
/home/delan/cbook/cbook-main.c:182: undefined reference to `mysql_fetch_row'
cbook-main.o: In function `main':
/home/delan/cbook/cbook-main.c:287: undefined reference to `mysql_init'
/home/delan/cbook/cbook-main.c:289: undefined reference to
`mysql_real_connect'
/home/delan/cbook/cbook-main.c:290: undefined reference to `mysql_select_db'
/home/delan/cbook/cbook-main.c:297: undefined reference to `mysql_close'
collect2: ld returned 1 exit status
make: *** [all] Error 1

I have read the following page already and unfortunately, I am still
unable to compile it:
http://dev.mysql.com/doc/refman/5.0/en/c-api-linking-problem s.html

If anyone could help me with this it would be greatly appreciated.

- --
Thanks and best regards,
Delan Azabani
http://azabani.com/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.16 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJNJ/DQAAoJEAVIdHYYQWqnYTQP/10GHt7lmBjynjTXfypg +EHg
+z0mW3yr0J6TIBYasYdNSPWr2y6LCu1WqM2hP350pxj3ILQwJTZWldL9ZZZZ 3uyo
minSTobxcLU7Q2NCq5yJI6nTvW8WbBUlsAuSLiFrJSRSljH7roL4i2hLqrx6 6GkB
OCwoykznGcWsYKrTnhcszCQ2opK2YVf3T4duImynoYfFsZWP5JYyse5kGBJh XFaR
vUGpbNu59EFRylyDpRkMvQDUv45Y+cBpmruz+OUpit5eoyOxg3aUd9Bdm+FI HnMQ
c5QTz/g8kwfQJ5eOkWZhHfvO8jBLOdPFqkd9vdayw3kZihEXKMHTco8pFQRm /F2q
4w0TPCAaedN+1gspS+1Hon5ADBuz8q0J+LWkiOWcPKj6NL4NXOiQwQd8PZdy NOmM
VhH1/kF4Y5wCKvl/tQJWOjjJO31LOX9Lmdz8cP4sI8opHbJ4K4WPWj31spkF kF7c
NYwr+S6X+BLFvrKcunyIHYe+4btnt57BtMouTyNb8mb59rQFhL7h0LiUPhrz pwxr
wk1byf7Ov0OyVE7b2bc5+bIAf4MnaPVC+TGTezPFLbpx1tE40ZWlBxAjxPFm IuvY
ZjB7Rtyc4+bW2fMiM4GFVQODsvJCB9x/tUNOw7I2jyKQI5pBczkqBxiNqswV M7yE
yc77+eyvX6IgeZ9svzvO
=y9dU
-----END PGP SIGNATURE-----

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org

Re: linking to mysql in C

am 15.01.2011 00:33:23 von Luciano Furtado

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

What's the output of mysql_config --libs for you?

On 11-01-08 00:06, Delan Azabani wrote:
> Hi all,
>
> This is a novice problem I'm having with compiling a C CGI program with
> MySQL on my Gentoo box.
>
> I have a simple source so far:
>
> * cbook-main.c: http://pastebin.com/vnT6j1z2
> * cbook-main.h: http://pastebin.com/4BnyWs27
> * Makefile: http://pastebin.com/m973gbjG
>
> When compiling I receive undefined reference errors:
>
> delan@delan2 ~/cbook $ make
> make cbook-main
> make[1]: Entering directory `/home/delan/cbook'
> cc -g `pkg-config --cflags libconfuse glib-2.0` `mysql_config --cflags`
> -c cbook-main.c
> make[1]: Leaving directory `/home/delan/cbook'
> cc `pkg-config --libs libconfuse glib-2.0` `mysql_config --libs` -o
> cbook.cgi cbook-main.o
> cbook-main.o: In function `myerror':
> /home/delan/cbook/cbook-main.c:61: undefined reference to `mysql_error'
> /home/delan/cbook/cbook-main.c:61: undefined reference to `mysql_errno'
> cbook-main.o: In function `myescape':
> /home/delan/cbook/cbook-main.c:67: undefined reference to
> `mysql_real_escape_string'
> cbook-main.o: In function `myquery':
> /home/delan/cbook/cbook-main.c:85: undefined reference to `mysql_query'
> cbook-main.o: In function `createDatabase':
> /home/delan/cbook/cbook-main.c:90: undefined reference to `mysql_select_db'
> cbook-main.o: In function `pageHome':
> /home/delan/cbook/cbook-main.c:144: undefined reference to
> `mysql_store_result'
> /home/delan/cbook/cbook-main.c:146: undefined reference to `mysql_fetch_row'
> /home/delan/cbook/cbook-main.c:160: undefined reference to
> `mysql_free_result'
> cbook-main.o: In function `pageSessions':
> /home/delan/cbook/cbook-main.c:181: undefined reference to
> `mysql_store_result'
> /home/delan/cbook/cbook-main.c:182: undefined reference to `mysql_fetch_row'
> cbook-main.o: In function `main':
> /home/delan/cbook/cbook-main.c:287: undefined reference to `mysql_init'
> /home/delan/cbook/cbook-main.c:289: undefined reference to
> `mysql_real_connect'
> /home/delan/cbook/cbook-main.c:290: undefined reference to `mysql_select_db'
> /home/delan/cbook/cbook-main.c:297: undefined reference to `mysql_close'
> collect2: ld returned 1 exit status
> make: *** [all] Error 1
>
> I have read the following page already and unfortunately, I am still
> unable to compile it:
> http://dev.mysql.com/doc/refman/5.0/en/c-api-linking-problem s.html
>
> If anyone could help me with this it would be greatly appreciated.
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJNMN1DAAoJENgwSj9ZOOwrZJ0IAMdTAEhptXErCz/4paKG GO+L
mDScIXYvTLNOStrB8zT+SChtMVzgr8V1E8B7MCEz2Ra0XBErvb63JvQ3kLQv mFX8
GBNFFUPRwhyi7pWq+rtj6gRt3Dz0tLAeV6W1Ui/WMJRg5AHopHXm0p2CVWO1 vTvI
oiWaaUSCa+k8Sp5YRr551ypKXGcqW5CGGp4utXUyrYRYLNJ4/Ce2VYt/lcDE 59Zm
dZXrlXMsiSKf1sTtXkVz5J08GfPIMH9oUnNOKvNrwsI6nf2I7gfCSMBqOAhC AOy1
WGKUJ/gGQ/VjRZI8FdB0dQrJ+DBJwOjBFJvnJAJbvjwATOeqMT1ZQeh6tthU Uus=
=Er8U
-----END PGP SIGNATURE-----


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org

Re: linking to mysql in C

am 15.01.2011 17:03:11 von walter harms

You are missing the libmysqlclient.
I guess the problem is your makefile. make != shell

You CFLAGS should have something like this:
-L/usr/lib/mysql -lmysqlclient

(Actualy it should be LDFLAGS and LOADLIBES)

something like $(shell pkg-config --cflags $(packages) ) should work
further reading: http://www.gnu.org/software/make/manual/make.html#Shell-Func tion

hope that helps,
re,
wh

Am 08.01.2011 06:06, schrieb Delan Azabani:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi all,
>
> This is a novice problem I'm having with compiling a C CGI program with
> MySQL on my Gentoo box.
>
> I have a simple source so far:
>
> * cbook-main.c: http://pastebin.com/vnT6j1z2
> * cbook-main.h: http://pastebin.com/4BnyWs27
> * Makefile: http://pastebin.com/m973gbjG
>
> When compiling I receive undefined reference errors:
>
> delan@delan2 ~/cbook $ make
> make cbook-main
> make[1]: Entering directory `/home/delan/cbook'
> cc -g `pkg-config --cflags libconfuse glib-2.0` `mysql_config --cflags`
> - -c cbook-main.c
> make[1]: Leaving directory `/home/delan/cbook'
> cc `pkg-config --libs libconfuse glib-2.0` `mysql_config --libs` -o
> cbook.cgi cbook-main.o
> cbook-main.o: In function `myerror':
> /home/delan/cbook/cbook-main.c:61: undefined reference to `mysql_error'
> /home/delan/cbook/cbook-main.c:61: undefined reference to `mysql_errno'
> cbook-main.o: In function `myescape':
> /home/delan/cbook/cbook-main.c:67: undefined reference to
> `mysql_real_escape_string'
> cbook-main.o: In function `myquery':
> /home/delan/cbook/cbook-main.c:85: undefined reference to `mysql_query'
> cbook-main.o: In function `createDatabase':
> /home/delan/cbook/cbook-main.c:90: undefined reference to `mysql_select_db'
> cbook-main.o: In function `pageHome':
> /home/delan/cbook/cbook-main.c:144: undefined reference to
> `mysql_store_result'
> /home/delan/cbook/cbook-main.c:146: undefined reference to `mysql_fetch_row'
> /h

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org