linux - 编译时提示头文件#include <mysql/mysql.h>不存在,百度之后也没解决

查看:442
本文介绍了linux - 编译时提示头文件#include <mysql/mysql.h>不存在,百度之后也没解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

#include <mysql/mysql.h>
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW *row;

char *server = "localhost";
char *user = "root";
char *password = "1";

conn = mysql_init(NULL);
if(!mysql_real_connect (conn,server,user,password,database,0,NULL,0))
{
    fprintf(stderr,"%s\n",mysql_error(conn));
    exit(1);
}
if(mysql_real_query(conn,"select * from student"))
{
    fprintf(stderr,"%s\n",mysql_error(conn));
    exit(1);
}
res = mysql_use_result(conn);
while((row = mysql_fetch_row(res)) != NULL)
{
    printf("%s\t%s\t%s\n",row[0],row[1],row[2]);
}
mysql_free_result(res);
mysql_close(conn);

解决方案

$ sudo yum install mysql-devel -y    //RHEL,Centos,Fedora
$ sudo apt-get install libmysqlclient-dev -y  //Ubuntu

如果已经安装成功了,找到mysql.h的文件路径,-I 编译即可

$ sudo  find /usr/ -name 'mysql.h'
$ gcc -I/usr/include/mysql ...

这篇关于linux - 编译时提示头文件#include &lt;mysql/mysql.h&gt;不存在,百度之后也没解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆