0
當T嘗試運行我的C++程序連接到MYSQL服務器時,出現錯誤。這是我的代碼。Visual Studio C++連接到MYSQL服務器
#include "stdafx.h"
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/opencv.hpp"
#include <cmath>
#include <iostream>
#include "my_global.h"
#include "mysql.h"
int main() {MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "server";
char *user = "user";
char *password = "password"; // got tot keep my data secret
char *database = "cpp_test";
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 -1;
}
// send SQL query
if(mysql_query(conn, "select * from cpp_testTAB"))
{
fprintf(stderr, "%s\n", mysql_error(conn));
return -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 %s %s %s\n", row[0], row[1], row[2], row[3]);
}
// close connection
mysql_free_result(res);
mysql_close(conn);
return 0;
}
這裏是我另外包括目錄
C:\Program Files (x86)\MySQL\MySQL Server 5.6\include
C:\Program Files (x86)\MySQL\Connector.C++ 1.1\include
附加庫目錄
C:\Program Files (x86)\MySQL\MySQL Server 5.6\lib
C:\Program Files (x86)\MySQL\Connector.C++ 1.1\lib\opt
附加依賴
libmysql.lib
mysqlcppconn-static.lib
有,我有,當我嘗試錯誤跑 該程序。
Error 1 error LNK2019: unresolved external symbol mysql_close referenced in function main
Error 2 error LNK2019: unresolved external symbol mysql_free_result referenced in function main
Error 3 error LNK2019: unresolved external symbol mysql_fetch_row referenced in function main
Error 4 error LNK2019: unresolved external symbol mysql_use_result referenced in function main
Error 5 error LNK2019: unresolved external symbol mysql_query referenced in function main
Error 6 error LNK2019: unresolved external symbol mysql_error referenced in function main
Error 7 error LNK2019: unresolved external symbol mysql_real_connect referenced in function main
Error 8 error LNK2019: unresolved external symbol mysql_init referenced in function main
Error 9 error LNK1120: 8 unresolved externals C:\Users\Lahiru\documents\visual studio 2010\Projects\Level4-Project\x64\Debug\Level4-Project.exe
我無法解決此問題。如果任何人都可以向我展示錯誤或示例教程鏈接,那將很棒。
看看最後一個錯誤。它在路徑中有'x64',而在其他錯誤中有'Program Files(x86)'。看起來你已經混淆了32位和64位版本。 – PaulMcKenzie 2014-10-12 13:59:52
我評論了mysql連接代碼,其他代碼將用於'x64',並且我已經爲'x64'安裝了所有的mysql庫。但我認爲你說的是對的。我怎樣才能解決這個問題 ?我有x64 machaine – user3565768 2014-10-12 14:08:53
如果它是一個64位應用程序,那麼這些庫必須是64位的。同樣,這些庫的路徑對我來說是非常可疑的,因爲它們被放置在32位應用程序使用的目錄中。 – PaulMcKenzie 2014-10-12 14:10:56