编辑:
我的问题是这篇文章底部的错误。
下面是我的附加包含目录
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小时就要完成这个项目了,我已经花了很多时间来尝试解决这个问题。
谢谢
发布于 2013-05-09 23:13:21
恕我直言,最后两个问题是编译器/链接器问题。我理解你的沮丧,因为我知道如何在早期编写代码,但对编译器/链接器一无所知。当你有时间的时候,花点时间读一读:
为了回答你的问题,我猜你是在Microsoft Visual Studio中这样做的:
mysql.lib ...在链接器部分的某个地方有一个“附加库”输入,您将能够识别它,因为kernel32.lib将对其进行整型处理。将mysql.lib添加到该部分。通过进入包含binaries..dll将为您提供新的问题,您无需担心。这通常通过设置正确的库目录来实现。许多c++库都会附带包含正确库的预编译的“静态”和“动态”文件夹。发布于 2013-05-09 21:06:33
这是由于链接器问题而发生的错误。链接器无法找到所需的静态或动态库 (mysql.lib、mysqlcppconn-static.lib、libmysql.dll和libmysql.lib)。的附加库设置是错误的。检查此站点,给出正确的路径Building MySQL Connector/C++ Windows Applications with Microsoft Visual Studio
https://stackoverflow.com/questions/16455350
复制相似问题