MySQL: MySQL 5.0 Reference Manual: Release 6.16.1 problems linking to the mysql client library
6.16.1. Problems linking to the mysql client library
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-lnslundefined first referenced symbol in filefloor/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.
Linking with the single-threaded Library (Libmysqlclient
) May lead to linker errors relatedPthread
Symbols. When using the single-threaded library, please compile your clientMysql_client_no_threads
Defined. This can be done on the command line by using-D
Option to the compiler, or in your source code before including the MySQL header files. This define shocould not be used when building for use with the thread-safe client library (Libmysqlclient_r
).
When you are linking an application program to use the mysql client library, you might get undefined reference Errors for symbols that startMySQL _
, 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 shoshould be able to solve this problem by adding-Ldir_path-lmysqlclient
At the end of your link command, whereDir_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 fromMysql_configMight indicate other libraries that shocould be specified on the link command as well.
If you getUndefined reference
Errors forUncompress
OrCompress
Function, add-LZ
To the end of your link command and try again.
If you getUndefined reference
Errors for a function that shocould exist on your system, suchConnect
, Check the manual page for the function in question to determine which libraries you shoshould add to the link command.
You might getUndefined 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.17, "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 startMySQL _
Or indicate thatMysqlclient
Library can't be found, it means that your system can't find the sharedLibmysqlclient. 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 shoshould be sure that no other programs are using the dynamic libraries.