如何在我的位置修复 mysql 错误并在 codeblock c++ 上使用 mysql 而没有任何问题?当我包含 mysql.h 时,只有“MYSQL”、“MYSQL_RES”、“MYSQL_ROW”类开始工作。代码(main.cpp):
#include <stdio.h>
#include "mysql/mysql.h"
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "root";
char *password = "864630299";
char *database = "rpg";
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);
错误:
undefined reference to 'mysql_init@4'
undefined reference to 'mysql_real_connect@32'
undefined reference to 'mysql_error'...
设置:链接器 - 无,搜索目录有:“\usr\lib\mysql\”。
使用“MySQL Server 5.5”包含文件夹中的 mysql.h 和其他头文件,该文件夹已复制并粘贴到我的项目文件夹中,现在用作“#include”mysql/mysql.h”。
为什么我的mysql命令不起作用?:示例(mysql_query,mysql_real_connect ...)
提前致谢。
通过包含在 Settings->Compiler->Linker Settings->Add->libmysql.a 中并将 libmysql.dll 包含到我的项目文件夹中来修复我自己。:) 希望它对某人有所帮助。