gcc mysql_centos gcc编译 mysql 问题发现 | 学步园

一点点来:

编译不通过非常郁闷

20.7.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 -lmysqlclientat 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.

我的问题是在红色和紫色那两个地方搞定到,我装到是64位到linux ,新人看两一点make就去搞这个玩意直接悲剧了……还好mysql官网有类似的到问题

部分转自:http://dev.mysql.com/doc/refman/5.0/en/c-api-linking-problems.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值