[英]Linker error when connecting C to mysql
我想使用以下代碼將 C 連接到 mysql:
#include <C:\Program Files\MySQL\MySQL Connector C 6.0.2\include\my_global.h>
#include <C:\Program Files\MySQL\MySQL Connector C 6.0.2\include\mysql.h>
#include <stdio.h>
MYSQL *conn; /* pointer to connection handler */
int main ( int argc, char *argv[] )
{
conn = mysql_init ( NULL );
mysql_real_connect (
conn,"localhost","root","","operator", 3306, NULL,0 );
mysql_close ( conn );
return 0;
}
當我嘗試編譯時,我得到:
Error 3 error LNK2019: unresolved external symbol _mysql_real_connect@32 referenced in function _main C:\Users\kristel\Documents\Visual Studio 2010\Projects\database\database\database.obj database
Error 4 error LNK2019: unresolved external symbol _mysql_init@4 referenced in function _main C:\Users\kristel\Documents\Visual Studio 2010\Projects\database\database\database.obj database
好像缺少了什么,但我不知道什么時候。
我已經添加了圖片中的 mysqllib.lib,但問題仍然沒有解決。
另一個問題:在搜索時,我發現了一些有關 cmake 的信息。我的錯誤與 cmake 之間有什么關系嗎?
謝謝你。
雖然您在代碼中包含了 mySQL header 文件,但您沒有在鏈接選項中包含 mySQL 庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.