c – 找不到mysql.h文件

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

 /* 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);
    }

它的工作,但现在我面临另一个错误,如:

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。

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

你通常会在你的代码中使用mysql.h头,如下所示:

#include <mysql/mysql.h>

如果您不想在源代码中指定目录偏移量,则可以将-I标志传递给gcc(如果这是您正在使用的)来指定附加的include搜索目录,那么您不需要更改现有代码

例如。

gcc -I/usr/include/mysql ...
http://stackoverflow.com/questions/14604228/mysql-h-file-cant-be-found

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:c – 找不到mysql.h文件