MySQL: MySQL 5.0 Reference Manual: Release 6.16.1 problems linking to the mysql client library

Source: Internet
Author: User

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-LMTo the end of the compile/link line.

Linking with the single-threaded Library (Libmysqlclient) May lead to linker errors relatedPthreadSymbols. When using the single-threaded library, please compile your clientMysql_client_no_threadsDefined. This can be done on the command line by using-DOption 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-lmysqlclientAt the end of your link command, whereDir_pathRepresents 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 referenceErrors forUncompressOrCompressFunction, add-LZTo the end of your link command and try again.

If you getUndefined referenceErrors 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 referenceErrors 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 thatMysqlclientLibrary can't be found, it means that your system can't find the sharedLibmysqlclient. SoLibrary. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.