Link issues with the MySQL client library

Source: Internet
Author: User
Tags connect mysql client

When you link to an application to use the MySQL client library, you may encounter an undefined reference error starting with Mysql_, as follows:

/tmp/ccFKsdPa.o: 在函数`main'中:
/tmp/ccFKsdPa.o(.text+0xb): 对`mysql_init'的未定义引用。
/tmp/ccFKsdPa.o(.text+0x31): 对`mysql_real_connect'的未定义引用。
/tmp/ccFKsdPa.o(.text+0x57): 对`mysql_real_connect'的未定义引用。
/tmp/ccFKsdPa.o(.text+0x69): 对`mysql_error'的未定义引用。
/tmp/ccFKsdPa.o(.text+0x9a): 对`mysql_close'的未定义引用。

You should be able to resolve the problem by adding the "-ldir_path-lmysqlclient" option after the link command, where Dir_path represents the pathname of the directory where the client library resides. To determine the correct directory, try the following command:

Shell> Mysql_config--libs

The output from Mysql_config may indicate other libraries that should be specified on the link command.

For uncompressed or compressed functions, if you encounter an undefined reference error, add-lz after the link command, and try again.

If you encounter an undefined reference error for a function that should exist on the system, such as Connect, check the manual page of the related function to determine which libraries should be added to the link command.

For functions that do not exist on the system, you may encounter undefined reference errors, as follows:

MF_FORMAT.O (. text+0x201): An undefined reference to ' __lxstat '.

It usually means that your MySQL client library is compiled on a system that is not 100% compatible with your system. In this case, you should download the latest MySQL source distribution and compile your own MySQL.

When you try to execute a MySQL program, you may encounter run-time undefined reference errors. If this type of error indicates a symbol that starts with mysql_, or indicates that the Mysqlclient library was not found, this means that your system cannot find the shared libmysqlclient.so library. The correct way to do this is to notify the system to search for a shared library in the location of the library. Use the following methods that are compatible with your system:

• Add the path of the libmysqlclient.so directory to the LD_LIBRARY_PATH environment variable.

• Add the path of the libmysqlclient.so directory to the LD_LIBRARY environment variable.

• Copy the libmysqlclient.so to a directory that can be searched by the system, such as/lib, and then update the shared library information by performing Ldconfig.

Another way to solve this problem is to connect your program to the "-static" selection in a static way, or delete the dynamic MySQL library before linking the code. Before using the 2nd method, make sure that there are no other programs that use dynamic libraries.

Related Article

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.