visual c ++ 2010 mysql connect [英] visual c++ 2010 mysql connect
问题描述
我想使用Visual C ++与Visual Studio 2010建立一个mysql连接。
我看过这个问题几次,但我不能
为什么没有任何真正有用的和容易的分步教程呢?
然后我的意思是:正确的下载链接,保存文件的地方。要添加到项目中的文件和正确的代码。
我尝试使用了许多不同的c ++连接器甚至是完整的软件包。但没有成功。我在属性中将include文件夹添加到C ++ Additional Include Directories,我在Linker Additional Library Directories中添加了包含libmysql.lib的lib文件夹,并将libmysql.lib添加到Linker Input Additional Dependancies。
我尝试使用以下代码:
#include< iostream>
#include< fstream>
#include< vector>
#includerapidxml.hpp
#includerapidxml_print.hpp
#includemy_global.h//首先包含此文件以避免出现问题
#includemysql .h// MySQL Include文件
#includeXMLFile.h
using namespace std;
using namespace rapidxml;
int main(){
MYSQL * mysql;
MYSQL_RES * result;
MYSQL_ROW row;
string server =localhost
string username =root;
string password =;
string database =test;
int port = 3306;
mysql = mysql_init(0);
if(!mysql_real_connect(mysql,server.c_str(),username.c_str(),password.c_str(),database.c_str(),port,NULL,0)){
fprintf ,%s\\\
,mysql_error(mysql));
return 0;
}
//进一步的代码应该跟随,但我已经得到错误
cin.get();
return(0);
}
但我已经得到错误:
错误4错误LNK2019:无法解析的外部符号_mysql_error @ 4
在函数_main中引用
是正确的
您必须为链接器输入添加libmysql.lib附加的依赖关系:
项目属性> linker> input>其他依赖项。
然后复制libmysql.dll在exe文件夹(在PATH中定义的文件夹)如'c:\windows'
您的问题将解决。 / p>
您可以在安装mysql的文件夹中找到libmysql.dll。
mysql.h头。如果你想使用连接器++头文件会有所不同。
I want to make a mysql connection using visual c++ with visual studio 2010.
I have seen this question asked a couple of times, but I can't seem to figure it out.
Why aren't there any really useful and easy step by step tutorials for this? And then I mean like: the right download links, the places to save the files. The files to add to your project and the right code to write.
I tried using a lot of different c++ connectors or even the full packages. But without success. I added in the properties the "include" folder to "C++ Additional Include Directories", I added the "lib" folder which includes "libmysql.lib" to the "Linker Additional Library Directories" and I added "libmysql.lib" to the "Linker Input Additional Dependancies".
I tried using code like:
#include <iostream>
#include <fstream>
#include <vector>
#include "rapidxml.hpp"
#include "rapidxml_print.hpp"
#include "my_global.h" // Include this file first to avoid problems
#include "mysql.h" // MySQL Include File
#include "XMLFile.h"
using namespace std;
using namespace rapidxml;
int main () {
MYSQL *mysql;
MYSQL_RES *result;
MYSQL_ROW row;
string server = "localhost";
string username = "root";
string password = "";
string database = "test";
int port = 3306;
mysql = mysql_init(0);
if ( !mysql_real_connect( mysql, server.c_str(), username.c_str(), password.c_str(), database.c_str(), port, NULL, 0 ) ) {
fprintf( stderr, "%s\n", mysql_error( mysql ) );
return 0;
}
//further code should follow but i already get errors
cin.get();
return(0);
}
but i already get errors like:
Error 4 error LNK2019: unresolved external symbol _mysql_error@4 referenced in function _main
that's right
u have to add 'libmysql.lib' to Linker Input Additional Dependancies in: project properties> linker> input> additional dependencies . then copy libmysql.dll in exe folder (the folder defined in PATH) such as 'c:\windows'
your problem will be solved.
you can find libmysql.dll in the folder you installed mysql .
what told above in for problem of using "mysql.h" header. if u want to use connector++ headers it would be different.
这篇关于visual c ++ 2010 mysql connect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!