0

我的源代码导致:

// 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 _mysql_real_connect@32
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 ==========

我不认为来源有问题,我只需要有关如何找出问题所在的帮助。

4

1 回答 1

1

您缺少对库的引用。C 连接器应该带有一个 .lib,将其添加到链接器的附加输入中

于 2011-05-24T00:49:24.023 回答