LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 895|回复: 1

关于 mysql C API的 问题

[复制链接]
发表于 2005-10-26 01:27:07 | 显示全部楼层 |阅读模式
  1. #include <mysql/mysql.h>
  2. #include <stdio.h>

  3. int main()
  4. {
  5.     MYSQL mysql;

  6.     mysql_init(&mysql);
  7.     mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"your_prog_name");
  8.     if (!mysql_real_connect(&mysql,"host","user","passwd","database",0,NULL,0))
  9.     {
  10.         fprintf(stderr, "Failed to connect to database: Error: %s\n",
  11.             mysql_error(&mysql));
  12.     }

  13.     return 0;
  14. }
复制代码

以上代码来自mysql的 manual
我编译不通过

  1. /tmp/ccojokYy.o(.text+0x29): In function `main':
  2. : undefined reference to `mysql_init'
  3. /tmp/ccojokYy.o(.text+0x47): In function `main':
  4. : undefined reference to `mysql_options'
  5. /tmp/ccojokYy.o(.text+0x8d): In function `main':
  6. : undefined reference to `mysql_real_connect'
  7. /tmp/ccojokYy.o(.text+0xa4): In function `main':
  8. : undefined reference to `mysql_error'
  9. collect2: ld returned 1 exit status

复制代码
 楼主| 发表于 2005-10-26 10:54:55 | 显示全部楼层
原来在编译的时候要加-lmysqlclient
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表