2011-05-24 110 views
0

我的源代碼,結果是:Visual C++ MySQL連接器/ C錯誤?

// MySQL.cpp : Defines the entry point for the console application. 
// 

#include <iostream> 
#include <winsock.h> 
#include <string> 
#include <sstream> 
#include <stdio.h> 
#include <mysql.h> 

#define TABLE_OF_INTEREST "some_table" 
#define SERVER_NAME "mysql_server" 
#define DB_USER "user" 
#define DB_USERPASS "pa55w0rd" 
#define DB_NAME "db_name" 
#define NEWLINE "\n" 

using namespace std; 

int main() 
{ 
    MYSQL *hnd = NULL; // mysql connection handle 
    const char *sinf = NULL; // mysql server information 
    if(!mysql_real_connect(hnd, SERVER_NAME, DB_USER, DB_USERPASS, DB_NAME, 0, NULL, 0) 
     cout << "Something happened."; 
    return 0; 
} 

錯誤:

1>------ Build started: Project: MySQL, Configuration: Release Win32 ------ 
1> MySQL.cpp 
1>MySQL.obj : error LNK2001: unresolved external symbol [email protected] 
1>c:\users\josiah\documents\visual studio 2010\Projects\MySQL\Release\MySQL.exe : fatal error LNK1120: 1 unresolved external 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

我不認爲與源有問題,我只需要對如何找出其中的問題是幫助。

回答

1

您錯過了對lib的引用。 C連接器應該帶有一個.lib文件,將它添加到鏈接器的附加輸入中

+0

.lib將被調用什麼? – Yoshiyahu 2011-05-24 01:02:06

+0

libmysql.lib,它的可能位置是C:\ Program Files文件(x86)\ MySQL \ MySQL連接器C x.x.x \ lib – Avery3R 2011-05-24 01:28:14

+0

啊,不,我已經添加了libmysql.lib整個時間。 – Yoshiyahu 2011-05-24 01:59:16