Linux下C连接MySQL出现错误解决一例

WBOY
Release: 2016-06-07 16:53:19
Original
960 people have browsed it

在Linux下C连接MySQL出现问题如下:编译成功后,运行程序,出现./connect: error while loading shared libraries: libmysqlclie

在Linux下C连接MySQL出现问题如下:

编译成功后,运行程序,出现./connect: error while loading shared libraries: libmysqlclient.so.15: cannot open shared object file: No such file or directory.

出现上面的错误是因为系统运行的时候没有找到程序运行所需要的libmysqlclient.so.15运行库文件,解决方法有两个:

方法一:直接把libmysqlclient.so.15这个文件拷贝到系统指定的/usr/lib库文件目录中。

方法二:设置/etc/ld.so.conf文件,编辑该文件,,在文件中加入libmysqlclient.so.15所在目录,保存退出。需要注意的是,每次改动ld.so.conf之后需要运行ldconfig来确认刷新。

方法三:Add /usr/local/mysql/lib/mysql to you LD_LIBRARY_PATH environment variable

ldconfig使用方法: ldconfig [options] [libs]

命令ldconfig决定位于目录/usr/lib和/lib下的共享库所需的运行的链接,这些链接在命令行上的libs指定并被保存在 /etc/ld.so.conf中。命令ldconfig和动态链接/装载工具ld.so协同工作,一起来创建和维护对最新版本共享库的链接。

ldconfig的两个选项

-p:仅打印出文件/etc/ld.so.cache的内容,此文件是ld.so所知道的共享库的当前列表
-v:更新/etc/ld.so.cache的内容,列出每个库的版本号,扫描的目录和所有创建和更新的链接

附加信息:

在安装mysql时,运行"./configure" 时指定参数的问题(只介绍一部分,其他的参数请输入:"./configure --help"来查询)

./configure --prefix=/usr --sysconfdir=/etc
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc. You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.
Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--datadir=DIR read-only architecture-independent data [PREFIX/share]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
--infodir=DIR info documentation [PREFIX/info]
--mandir=DIR man documentation [PREFIX/man]

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!