zoukankan      html  css  js  c++  java
  • MySQL :: MySQL 5.0 Reference Manual :: 20.6.16.1 Problems Linking to the MySQL Client Library

    MySQL :: MySQL 5.0 Reference Manual :: 20.6.16.1 Problems Linking to the MySQL Client Library

    20.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 -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.

    Linking with the single-threaded library (libmysqlclient) may lead to linker errors related to pthread symbols. When using the single-threaded library, please compile your client with MYSQL_CLIENT_NO_THREADS defined. This can be done on the command line by using the -D option to the compiler, or in your source code before including the MySQL header files. This define should 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 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.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 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 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 should be sure that no other programs are using the dynamic libraries.

  • 相关阅读:
    两次动态输入和while的结合使用
    索引切片步长
    12.⽤户登陆(三次输错机会)且每次输错误时显示剩余错误次数(提示:使⽤字符串格式化)
    输出1-100的所以奇数或偶数
    求1-2+3-4+5 ... 99的所有数的和
    求1-100所有数的和
    三次登录机会
    while输入12345689
    while和格式化输出的复合使用
    44
  • 原文地址:https://www.cnblogs.com/lexus/p/2950180.html
Copyright © 2011-2022 走看看