您的位置:首页 > 数据库 > MySQL

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

2017-02-27 10:12 549 查看
   转自: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代码  


#include <stdlib.h>  

  

#include "mysql.h"  

  

int main(void){  

        MYSQL *conn_ptr;  

  

        conn_ptr=mysql_init(NULL);  

        if(!conn_ptr){  

                fprintf(stderr,"mysql_init failed \n");  

                return  EXIT_FAILURE;  

        }  

  

        conn_ptr  = mysql_real_connect(conn_ptr,"localhost","root","111111","mysql",0,NULL,0);  

  

        if(conn_ptr){  

                printf("Connection success\n");  

        }else{  

                printf("Connection failed\n");  

        }  

  

        mysql_close(conn_ptr);  

        return EXIT_SUCCESS;  

}  

 编译

gcc -o testmysql testmysql.c

Java代码  


testmysql.c:4:19: fatal error: mysql.h: No such file or directory  

compilation terminated.  

 

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

C代码  


/tmp/ccW7qMov.o: In function `main':  

testmysql.c:(.text+0x11): undefined reference to `mysql_init'  

testmysql.c:(.text+0x8f): undefined reference to `mysql_real_connect'  

testmysql.c:(.text+0xc0): undefined reference to `mysql_close'  

collect2: ld returned 1 exit statu  

 

最后修改

C代码  


gcc -o testmysql testmysql.c -I/usr/include/mysql/ -lmysqlclient -Wall -g  

成功
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐