When linking with the C API, the following errors may occur on some systems:
gcc -g -o client test.o -L/usr/local/lib/mysql \ -lmysqlclient -lsocket -lnsl Undefined first referenced symbol in file floor /usr/local/lib/mysql/libmysqlclient.a(password.o) ld: fatal: Symbol referencing errors. No output written to client
If this happens on your system, you must include the math
library by adding -lm
to the end of the
compile/link line.
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
path name 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.11, “Installing MySQL from Source”.
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 theLD_LIBRARY_PATH
environment variable.Add the path to the directory where
libmysqlclient.so
is located to theLD_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 executingldconfig
.