Linux使用C语言链接MsSQL

1.安装gcc编译器

yum install gcc

2.下载freetds

wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-patched.tar.gz

3.安装

tar xzf freetds-patched.tar.gz
./configure --with-tdsver=7.4 --enable-msdblib
make&&make install
 
填坑:
1.编译遇到如下错误:
start.c:(.text+0x27b): undefined reference to `dbinit'
start.c:(.text+0x280): undefined reference to `dblogin'
start.c:(.text+0x29c): undefined reference to `dbsetlname'
start.c:(.text+0x2b4): undefined reference to `dbsetlname'
start.c:(.text+0x2cc): undefined reference to `tdsdbopen'
start.c:(.text+0x2f4): undefined reference to `dbuse'
start.c:(.text+0x31a): undefined reference to `dbcmd'
start.c:(.text+0x326): undefined reference to `dbsqlexec'
start.c:(.text+0x332): undefined reference to `dbresults'
start.c:(.text+0x357): undefined reference to `dbbind'
start.c:(.text+0x36f): undefined reference to `dbclose'

解决方法:

编译的时候带上库目录

gcc -o start start.c -L/usr/local/lib/ -lsybdb

2.执行的时候遇到如下错误:

error while loading shared libraries: libsybdb.so.5: cannot open shared object file: No such file or directory

解决方法:

建立lib目录的链接

vim /etc/ld.so.conf.d/freetds.conf

添加/usr/local/lib后保存退出,之后执行

ldconfig

再编译即可通过

posted @ 2018-03-05 16:43  猫头老鹰  阅读(471)  评论(0编辑  收藏  举报