找不到mysql.h文件' [英] mysql.h file can't be found

查看:91
本文介绍了找不到mysql.h文件'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 ubuntu 12.04 中安装 c++ 和 mysql 之间的连接.我已经安装了 mysql-client、mysql-server、libmysqlclient15-dev、libmysql++-dev.但是当我尝试编译代码时出现错误:mysql.h 没有这样的文件.我查看了文件夹,有 mysql.h 文件,我不明白为什么找不到它.这是我的代码:

i'm trying to install connection between c++ and mysql in ubuntu 12.04. i've installed mysql-client, mysql-server, libmysqlclient15-dev, libmysql++-dev. but when i try to compile the code i got the error: mysql.h there is no such file. i looked in the folders, there is mysql.h file, i can't understand why it can't find it. here is my code:

 /* Simple C program that connects to MySQL Database server*/
    #include <mysql.h>
    #include <stdio.h>

    main() {
      MYSQL *conn;
      MYSQL_RES *res;
      MYSQL_ROW row;

      char *server = "localhost";
      char *user = "root";
      //set the password for mysql server here
      char *password = "*********"; /* set me first */
      char *database = "Real_flights";

      conn = mysql_init(NULL);

      /* Connect to database */
      if (!mysql_real_connect(conn, server,
            user, password, database, 0, NULL, 0)) {
          fprintf(stderr, "%s\n", mysql_error(conn));
          exit(1);
      }

      /* send SQL query */
      if (mysql_query(conn, "show tables")) {
          fprintf(stderr, "%s\n", mysql_error(conn));
          exit(1);
      }

      res = mysql_use_result(conn);

      /* output table name */
      printf("MySQL Tables in mysql database:\n");
      while ((row = mysql_fetch_row(res)) != NULL)
          printf("%s \n", row[0]);

      /* close connection */
      mysql_free_result(res);
      mysql_close(conn);
    }

它奏效了,但现在我面临另一个错误,例如:

it's worked, but now i'm facing another error like :

mysql.c: In function ‘main’:
mysql.c:21: warning: incompatible implicit declaration of built-in function ‘exit’
mysql.c:27: warning: incompatible implicit declaration of built-in function ‘exit’
/tmp/ccinQBp8.o: In function `main':
mysql.c:(.text+0x3e): undefined reference to `mysql_init'
mysql.c:(.text+0x5e): undefined reference to `mysql_real_connect'
mysql.c:(.text+0x70): undefined reference to `mysql_error'
mysql.c:(.text+0xa5): undefined reference to `mysql_query'
mysql.c:(.text+0xb7): undefined reference to `mysql_error'
mysql.c:(.text+0xe7): undefined reference to `mysql_use_result'
mysql.c:(.text+0x11c): undefined reference to `mysql_fetch_row'
mysql.c:(.text+0x133): undefined reference to `mysql_free_result'
mysql.c:(.text+0x141): undefined reference to `mysql_close'
collect2: ld returned 1 exit status

推荐答案

libmysqlclient-dev Ubuntu 包中的 mysql.h 文件位于 /usr/include/mysql/mysql.h.

The mysql.h file from the libmysqlclient-dev Ubuntu package is located at /usr/include/mysql/mysql.h.

这不是编译器的标准搜索路径,但是 /usr/include 是.

This is not a standard search path for compilers, however /usr/include is.

您通常在代码中使用 mysql.h 标头,如下所示:

You'd typically use the mysql.h header in your code like this:

#include <mysql/mysql.h>

如果您不想在源代码中指定目录偏移量,您可以将 -I 标志传递给 gcc(如果您正在使用)以指定一个额外的包含搜索目录,然后您就不需要更改现有代码.

If you don't want to specify the directory offset in your source, you can pass the -I flag to gcc (If that's what you are using) to specify an additional include search directory, and then you wouldn't need to change your existing code.

例如

gcc -I/usr/include/mysql ...

这篇关于找不到mysql.h文件&amp;#39;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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