![](/img/trans.png)
[英]VSCode c++ mysql.h undefined reference to 'mysql_init@4'
[英]MySQL and C : undefined reference to `_mysql_init@4'|
我正在嘗試編寫一個簡單的C腳本來從MySQL數據庫獲取值,但是會拋出此錯誤“對'_mysql_init @ 4的未定義引用”
不知道我是否未鏈接到應有的鏈接? 我的C語言知識很有限...
我在Windows上使用代碼塊,這是我的代碼:
#include <winsock.h>
#include <C:\mysql\include\mysql.h>
#include <stdio.h>
#include <string.h>
int main()
{
MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;
char query[80];
mysql_init(&mysql);
mysql_real_connect(&mysql,"localhost","user","pass","db",0,NULL,0);
sprintf(query,"SELECT src,dst FROM ipaudit");
mysql_real_query(&mysql,query,(unsigned int)strlen(query));
res = mysql_use_result(&mysql);
while(row = mysql_fetch_row(res))
printf("%s %sn",row[0],row[1]);
mysql_free_result(res);
return 0;
}
這是一個鏈接器錯誤,表明該鏈接器找不到函數mysql_init
。
確保您鏈接到libmysql.lib
或mysqlclient.lib
。 在Windows上構建時,還需要包含<my_global.h>
(請參見MySQL手冊中的同一頁)。
使用32位連接器: http : //www.mysql.com/downloads/connector/c/,並且不要忘記在#include <mysql.h>
之前#include <mysql.h>
#include <windows.h>
#include <mysql.h>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.