fatal error: mysql.h: No such file or directory

   转自:http://tangmingjie2009.iteye.com/blog/1521088


      我是在Ubuntu系统下测试的

      此系统下,mysql安装: apt-get install mysql-server 等了有10多分钟

      然后又装了mysql-client: apt-get install mysql-client

      还不够还需要mysql的开发包: apt-get install libmysql++

     没有权限的话sudo 你懂的

      敲下代码

C代码   收藏代码
  1. #include <stdlib.h>  
  2.   
  3. #include "mysql.h"  
  4.   
  5. int main(void){  
  6.         MYSQL *conn_ptr;  
  7.   
  8.         conn_ptr=mysql_init(NULL);  
  9.         if(!conn_ptr){  
  10.                 fprintf(stderr,"mysql_init failed \n");  
  11.                 return  EXIT_FAILURE;  
  12.         }  
  13.   
  14.         conn_ptr  = mysql_real_connect(conn_ptr,"localhost","root","111111","mysql",0,NULL,0);  
  15.   
  16.         if(conn_ptr){  
  17.                 printf("Connection success\n");  
  18.         }else{  
  19.                 printf("Connection failed\n");  
  20.         }  
  21.   
  22.         mysql_close(conn_ptr);  
  23.         return EXIT_SUCCESS;  
  24. }  

 编译

gcc -o testmysql testmysql.c

Java代码   收藏代码
  1. testmysql.c:4:19: fatal error: mysql.h: No such file or directory  
  2. compilation terminated.  

 

然后修改gcc -o testmysql testmysql.c  -I/usr/include/mysql/

C代码   收藏代码
  1. /tmp/ccW7qMov.o: In function `main':  
  2. testmysql.c:(.text+0x11): undefined reference to `mysql_init'  
  3. testmysql.c:(.text+0x8f): undefined reference to `mysql_real_connect'  
  4. testmysql.c:(.text+0xc0): undefined reference to `mysql_close'  
  5. collect2: ld returned 1 exit statu  

 

最后修改

C代码   收藏代码
  1. gcc -o testmysql testmysql.c -I/usr/include/mysql/ -lmysqlclient -Wall -g  

成功

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值