我的源代码导致:
// 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 ==========
我认为来源没有问题,我只需要帮助找出问题所在。
答案 0 :(得分:1)
您缺少对lib的引用。 C连接器应该带有.lib,将其添加到链接器的附加输入