编辑:
我的问题是这篇文章底部的错误。
继承我的其他包含目录
C:\Program Files\boost
C:\Program Files\MySQL\MySQL Connector C++ 1.1.3\include
C:\Program Files\MySQL\MySQL Server 5.6\include
其他图书馆目录
C:\Program Files\MySQL\MySQL Server 5.6\lib
C:\Program Files\MySQL\Connector C++ 1.1.2\lib\opt
其他依赖性
libmysql.lib
mysqlcppconn-static.lib
继承我的代码
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
#include <stdlib.h>
#include <Windows.h>
#include <mysql.h>
#include "mysql_connection.h"
#include <cppconn/driver.h>
#define host "localhost"
#define username "root"
#define password "root"
#define database "tests"
int main()
{
MYSQL* conn;
conn = mysql_init( NULL );
if( conn )
{
mysql_real_connect( conn, host, username, password, database, 0, NULL, 0 );
}
MYSQL_RES* res_set;
MYSQL_ROW row;
unsigned int i;
mysql_query( conn, "SELECT * FROM tbl_clients WHERE id = 1" );
res_set = mysql_store_result( conn );
unsigned int numrows = mysql_num_rows( res_set );
if( numrows )
{
row = mysql_fetch_row( res_set );
if( row != NULL )
{
cout << "Client ID : " << row[0] << endl;
cout << "Client Name: " << row[1] << endl;
}
}
if( res_set )
{
mysql_free_result( res_set );
}
if( conn )
{
mysql_close( conn );
}
return 0;
}
这些是我得到的错误
1>------ Build started: Project: okay, Configuration: Debug Win32 ------
1>welp.obj : error LNK2019: unresolved external symbol _mysql_num_rows@4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_init@4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_real_connect@32 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_query@8 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_store_result@4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_free_result@4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_fetch_row@4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_close@4 referenced in function _main
1>C:\Users\Damian\documents\visual studio 2012\Projects\okay\Debug\okay.exe : fatal error LNK1120: 8 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
请帮助,这个项目将在我的课程大约48小时到期,而且我花了很多时间试图解决这个问题。
由于
答案 0 :(得分:2)
尊敬的是,您的最后两个问题是编译器/链接器问题。我理解你的挫败感,因为我知道如何提前编码但对编译器/链接器一无所知。当你花点时间阅读:
要回答你的问题,我猜你在Microsoft Visual Studio中这样做了:
mysql.lib
...在链接器部分的某个地方有一个“附加库”输入,你将能够识别它,因为kernel32.lib
将是int it。将mysql.lib
添加到该部分。通过转到包含二进制文件的mysql文件夹来确认名称。.dll
会为您提供一些您不必担心的新问题。这通常通过设置正确的库目录来实现。许多c ++库将附带包含正确库的预编译“静态”和“动态”文件夹。答案 1 :(得分:1)
由于链接器问题,这是错误发生。 链接器无法找到所需的静态或动态库( mysql.lib,mysqlcppconn-static.lib,libmysql.dll和libmysql.lib )。 其他lib设置错误。检查此网站正确提供路径Building MySQL Connector/C++ Windows Applications with Microsoft Visual Studio