Undefined reference error starting with mysql _ MySQL
Source: Internet
Author: User
Undefined reference error starting with mysql _ when you link to the application to use the MySQL client library, you may encounter an undefined reference error starting with mysql _, as shown below:
/Tmp/ccFKsdPa. o: In the 'main' function:
/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 can solve this problem by adding the "-Ldir_path-lmysqlclient" option after the link command. dir_path indicates the path name of the directory where the client library is located. To determine the correct directory, try the following command:
Shell> mysql_config -- libs
Output from mysql_config may indicate other libraries that should be specified on the link command.
For non-compression or compression functions, if an undefined reference error occurs, add-lz after the link command and try again.
For functions that should exist on the system (such as connect), if an undefined reference error occurs, check the related function manual page to determine which libraries should be added to the linked command.
For a function that does not exist on the system, an undefined reference error may occur, as shown below:
Mf_format.o (. text + 0x201): undefined reference to '_ lxstat.
This 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 code distribution version and compile MySQL by yourself.
When you try to execute the MySQL program, you may encounter an undefined reference error during the runtime. If these errors indicate the symbols starting with mysql _ or the mysqlclient library is not found, your system cannot find the shared libmysqlclient. so Library. The correction method is to notify the system to search for a shared library in the location where the database is located. Use the following methods to adapt to the system:
· Add the path of libmysqlclient. so to the LD_LIBRARY_PATH environment variable.
· Add the path of libmysqlclient. so to the LD_LIBRARY environment variable.
· Copy libmysqlclient. so to a directory that can be searched by the system, such as/lib, and then update the shared library information by executing ldconfig.
Another way to solve this problem is to link your program to the "-static" option statically, or delete the dynamic MySQL library before linking the code. Before using the 2nd method, ensure that no other programs in the dynamic library are used
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.