Ubuntu 下用C语言访问gdbm数据库编译注意事项(使用ndbm方式)

2989阅读 0评论2008-11-26 yangbajing
分类:数据库开发技术

  今天看书<Linux程序设计>(第三版)第七章,编译两个dbm1.c和dbm2.c文件时编译错误,提示:

$ gcc -ldbm -o dbm1 dbm1.c
/usr/bin/ld: cannot find -ldbm
collect2: ld returned 1 exit status

把-ldbm改成-lgdbm仍然报错,查了下资料终于找到解决方案。

  把dbm1.c文件里的头文件声明#include 注释掉,然后把#include 头文件的注释去掉,如下:

//#include
/* On some systems you need to replace the above with */
#include <gdbm-ndbm.h>

编译文件时需要使用如下命令

$ gcc -lgdbm_compat -o dbm1 dbm1.c


  Ubuntu中默认安装的是gdbm数据库,应该使用gdbm实现来访问数据库。若还是需要以dbm若ndbm方式来访问数据库的话就需要使用gdbm-ndbm.h头文件,编译链接时应使用-lgdbm_compat链接选项
上一篇:scim使用万能五笔
下一篇:C语言连接MySQL中文问题