:: DEVELOPER ZONE
When you are linking an application program to use the MySQL client
library, you might get undefined reference errors for symbols that
start with mysql_, such as those shown here:
/tmp/ccFKsdPa.o: In function `main': /tmp/ccFKsdPa.o(.text+0xb): undefined reference to `mysql_init' /tmp/ccFKsdPa.o(.text+0x31): undefined reference to `mysql_real_connect' /tmp/ccFKsdPa.o(.text+0x57): undefined reference to `mysql_real_connect' /tmp/ccFKsdPa.o(.text+0x69): undefined reference to `mysql_error' /tmp/ccFKsdPa.o(.text+0x9a): undefined reference to `mysql_close'
You should be able to solve this problem by adding
-Ldir_path -lmysqlclient at the end of your link
command, where dir_path represents the pathname
of the directory where the client library is located. To determine
the correct directory, try this command:
shell> mysql_config --libs
The output from mysql_config might indicate other libraries that should be specified on the link command as well.
If you get undefined reference errors for the
uncompress or compress
function, add -lz to the end of your link command
and try again.
If you get undefined reference errors for a
function that should exist on your system, such as
connect, check the manual page for the function
in question to determine which libraries you should add to the link
command.
You might get undefined reference errors such as
the following for functions that don't exist on your system:
mf_format.o(.text+0x201): undefined reference to `__lxstat'
This usually means that your MySQL client library was compiled on a system that is not 100% compatible with yours. In this case, you should download the latest MySQL source distribution and compile MySQL yourself. See Section 2.8, “MySQL Installation Using a Source Distribution”.
You might get undefined reference errors at runtime when you try to
execute a MySQL program. If these errors specify symbols that start
with mysql_ or indicate that the
mysqlclient library can't be found, it means that
your system can't find the shared
libmysqlclient.so library. The fix for this is
to tell your system to search for shared libraries where the library
is located. Use whichever of the following methods is appropriate
for your system:
Add the path to the directory where
libmysqlclient.so is located to the
LD_LIBRARY_PATH environment variable.
Add the path to the directory where
libmysqlclient.so is located to the
LD_LIBRARY environment variable.
Copy libmysqlclient.so to some directory that
is searched by your system, such as /lib, and
update the shared library information by executing
ldconfig.
Another way to solve this problem is by linking your program
statically with the -static option, or by
removing the dynamic MySQL libraries before linking your code.
Before trying the second method, you should be sure that no other
programs are using the dynamic libraries.
© 1995-2005 MySQL AB. All rights reserved.

User Comments
Warning: query failed: Unknown column 'user.firstname' in 'field list' in /data0/sites/live/web-main/lib/mysql-cxn.php on line 69
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /data0/sites/live/web-main/lib/docbook.php on line 245
Add your own comment.