| Mailing List | | Home | | MySQL General - General MySQL discussion | | MaxDB - Everything about MaxDB, formerly known as SAP DB | | MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP | | Java Help - Mostly related to the MySQL Connector/J driver | | ODBC - ODBC with the MySQL Connector/ODBC driver | | Perl - Perl support for MySQL with DBI and DBD::mysql | | MySQL++ - Programming with the C++ API to MySQL |
|
|
  | |  | Executing MySQL Commands From Within C Program | Executing MySQL Commands From Within C Program 2004-03-22 - By Rick Emery
Back I am attempting to interface between a simple C program and MySQL, but without luck.
I searched the MySQLforum archives to see if there was info specific to this problem. While there
were other folks who had problems connecting C/C++ to MySQL, none of the issue were similar to this,
that is linking to resolve external name table references.
Here is the actual program:
******* myprog.cc ***********
#include </usr/include/mysql/mysql.h >
int main(void)
{
MYSQL * myptr;
mysql_init(myptr);
return 0;
}
To compile it, I use:
$ gcc -c myprog.cc
To link/load:
$ ld myprog.o -o myprog
ld: warning: cannot find entry symbol _start; defaulting to 08048074
myprog.o: In function `main ':
myprog.o(.text+0xd): undefined reference to `mysql_init
If I try inclusion of the libmysqlclient.so library in the 'ld ' command, I get this:
$ ld -l /usr/lib/libmysqlclient.so myprog.o -o myprog
ld: cannot find -l/usr/lib/libmysqlclient.so
Or, if I compile and link/load in one step, I get this:
$ gcc -o myprog myprog.cc
/tmp/ccJ8uuvK.o: In function `main ':
/tmp/ccJ8uuvK.o(.text+0xd): undefined reference to `mysql_init '
collect2: ld returned 1 exit status
And "ls -l /usr/lib/libmysqlclient* " reveals:
rwxrwxrwx 1 root root 24 Mar 13 19:34 /usr/lib/libmysqlclient.so - >
libmysqlclient.so.12.0.0
lrwxrwxrwx 1 root root 24 Mar 13 19:34 /usr/lib/libmysqlclient.so.10 - >
libmysqlclient.so.10.0.0
-rwxr-xr-x 1 root root 224606 Feb 13 04:25 /usr/lib/libmysqlclient.so.10.0.0
lrwxrwxrwx 1 root root 24 Mar 13 19:34 /usr/lib/libmysqlclient.so.12 - >
libmysqlclient.so.12.0.0
-rwxr-xr-x 1 root root 249972 Feb 13 04:25 /usr/lib/libmysqlclient.so.12.0.0
lrwxrwxrwx 1 root root 26 Mar 13 19:34 /usr/lib/libmysqlclient_r.so - >
libmysqlclient_r.so.12.0.0
lrwxrwxrwx 1 root root 26 Mar 13 19:34 /usr/lib/libmysqlclient_r.so.10 - >
libmysqlclient_r.so.10.0.0
-rwxr-xr-x 1 root root 230560 Feb 13 04:25 /usr/lib/libmysqlclient_r.so.10.0.0
lrwxrwxrwx 1 root root 26 Mar 13 19:34 /usr/lib/libmysqlclient_r.so.12 - >
libmysqlclient_r.so.12.0.0
My setup is Red Hat Linux version 7.0. I used the latest mysql RPM (for Red Hat 7.0) from the mysql
web-site
Where can I go for help on this? If somebody has a suggestion, I 'm all ears. FYI, using MySQL with
PHP works like a charm from the command line and when called from a web-page. So, I know MySQL is
there, ready to do my bidding. I looked through the latestMySQL manual concerning the C/C++ API; no
help.
thanks
rick
--
MySQL General Mailing List
For list archives:
http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/mysql?unsub=mysql
@(protected)
|
|
 |