在Linux下C連接MySQL出現問題如下
編譯成功後運行程序出現/connect: error while loading shared libraries: libmysqlclientso: cannot open shared object file: No such file or directory
出現上面的錯誤是因為系統運行的時候沒有找到程序運行所需要的libmysqlclientso運行庫文件解決方法有兩個
方法一直接把libmysqlclientso這個文件拷貝到系統指定的/usr/lib庫文件目錄中
方法二設置/etc/nf文件編輯該文件在文件中加入libmysqlclientso所在目錄保存退出需要注意的是每次改動nf之後需要運行ldconfig來確認刷新
方法三Add /usr/local/mysql/lib/mysql to you LD_LIBRARY_PATH environment variable
ldconfig使用方法 ldconfig [options] [libs]
命令ldconfig決定位於目錄/usr/lib和/lib下的共享庫所需的運行的鏈接這些鏈接在命令行上的libs指定並被保存在 /etc/nf中命令ldconfig和動態鏈接/裝載工具ldso協同工作一起來創建和維護對最新版本共享庫的鏈接
ldconfig的兩個選項
p僅打印出文件/etc/ldsocache的內容此文件是ldso所知道的共享庫的當前列表
v更新/etc/ldsocache的內容列出每個庫的版本號掃描的目錄和所有創建和更新的鏈接
附加信息
在安裝mysql時運行/configure 時指定參數的問題(只介紹一部分其他的參數請輸入/configure help來查詢)
/configure prefix=/usr sysconfdir=/etc
Installation directories:
prefix=PREFIX install architectureindependent files in PREFIX
[/usr/local]
execprefix=EPREFIX install architecturedependent 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 readonly architectureindependent data [PREFIX/share]
sysconfdir=DIR readonly singlemachine data [PREFIX/etc]
sharedstatedir=DIR modifiable architectureindependent data [PREFIX/com]
localstatedir=DIR modifiable singlemachine data [PREFIX/var]
libdir=DIR object code libraries [EPREFIX/lib]
includedir=DIR C header files [PREFIX/include]
oldincludedir=DIR C header files for nongcc [/usr/include]
infodir=DIR info documentation [PREFIX/info]
mandir=DIR man documentation [PREFIX/man]
From:http://tw.wingwit.com/Article/program/MySQL/201311/29435.html