为什么在编译MySQL连接测试时会出现此错误?

时间:2015-10-08 09:07:55

标签: mysql c linux

fcts_mysql.h

MYSQL * cmd_mysql_init();

fcts_mysql.c

#include "fcts_mysql.h"
MYSQL *cmd_mysql_init(){
  return mysql_init(NULL);
}

mysql_test.c

#include "../lib/fcts_mysql.h"

#include <mysql.h>  
#include <stdio.h>
#include <stdlib.h>


int main() {
    MYSQL *cnxion;
    MYSQL_RES *res;
    MYSQL_ROW row;


    char *server   = "192.168.1.2";
    char *user     = "root";
    char *password = ""; 
    char *database = "test";

//  cnxion = mysql_init(NULL);     

    cnxion = cmd_mysql_init();

    if (!mysql_real_connect(cnxion, server,user, password, database, 0, NULL, 0)) {
        fprintf(stderr, "%s\n 404 \n", mysql_error(cnxion));return 1;
    }

    if (mysql_query(cnxion, "show tables")) {
        fprintf(stderr, "%s\n", mysql_error(cnxion));return 1;
    }
    res = mysql_use_result(cnxion);  

//  res    = cmd_mysql_select();

    printf("MySQL Tables in mysql database:\n");
//  FILE *file = fopen("liste_table.txt","w");
    while ((row = mysql_fetch_row(res)) != NULL){
    //  printf("%s \n", row[0]);fprintf(file,"%s \n",row[0]);
    }
//  fclose(file);   
    mysql_free_result(res);
    mysql_close(cnxion);

    return 0 ;
}
[root@xxxxx bin]# gcc  mysql_test.c $(mysql_config --libs) $(mysql_config --cflags)
In file included from mysql_test.c:1:
../lib/fcts_mysql.h:6: erreur: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token

1 个答案:

答案 0 :(得分:0)

编译器在MYSQL中找到它时,

"../lib/fcts_mysql.h"是未知的。

#include <mysql.h>前面移动#include "../lib/fcts_mysql.h"将解决问题。