代码: 全选
g++ -c main.cpp
在包含自 main.cpp:1 的文件中:
MysqlRecordSet.h:4:19: 错误: mysql.h:没有该文件或目录
In file included from main.cpp:1:
MysqlRecordSet.h:21: 错误: ISO C++ 不允许声明无类型的‘MYSQL’
MysqlRecordSet.h:21: 错误: expected ‘;’ before ‘*’ token
MysqlRecordSet.h:24: 错误: ISO C++ 不允许声明无类型的‘MYSQL’
MysqlRecordSet.h:24: 错误: expected ‘;’ before ‘*’ token
还是提示这个 奇怪了
我单独写个可以 可是用Makefile就不行
单独的如下
代码: 全选
/* Simple C program that connects to MySQL Database server*/
#include <mysql.h>
#include <stdio.h>
int main() {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "root";
char *password = "123456"; /* 此处改成你的密码 */
char *database = "mysql";
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));
return 0;
}
/* send SQL query */
if (mysql_query(conn, "show tables")) {
fprintf(stderr, "%s\n", mysql_error(conn));
return 0;
}
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);
return 1;
}
g++ $(mysql_config --cflags) connect.c -o connect $(mysql_config --libs)这样编译就OK了