visual c++ 2010 mysql connect
visual c++ 2010 mysql connect
我想使用 Visual C++ 和 Visual Studio 2010 建立 mysql 连接。
这个问题我看过几次,但我似乎想不通。
为什么没有任何真正有用且简单的分步教程?然后我的意思是:正确的下载链接,保存文件的位置。要添加到项目中的文件和要编写的正确代码。
我尝试使用许多不同的c ++连接器,甚至是完整的软件包。但没有成功。我在属性中添加了"include"文件夹到"C++附加包含目录",我将包含"libmysql.lib"的"lib"文件夹添加到"链接器附加库目录",并将"libmysql.lib"添加到"链接器输入附加依赖项"。
我尝试使用以下代码:
#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, "%sn", mysql_error( mysql ) );
return 0;
}
//further code should follow but i already get errors
cin.get();
return(0);
}
但是我已经收到以下错误:
错误4 错误 LNK2019:未解析的外部符号_mysql_error@4 在函数_main中引用
我不得不在VS 2008和VS 2010之间进行更改。
很多名字的变化。以下是一些更改:
#if (_MSC_VER == 1600)
#include "driver/mysql_public_iface.h"
#else
#include "mysql_driver.h"
#endif
namespace sql
{
class Connection;
#if (_MSC_VER == 1600)
class Driver;
#endif
namespace mysql
{
#if (_MSC_VER != 1600)
class MySQL_Driver;
#endif
}
}
#if (_MSC_VER == 1600)
mutable sql::Driver * m_p_sql_driver;
#else
mutable sql::mysql::MySQL_Driver * m_p_sql_driver;
#endif
void
initialize_db_driver() const
{
static bool driver_initialized = false;
if (!driver_initialized)
{
wxMutexLocker lock(sql_driver_mutex);
if (!driver_initialized)
{
// There is something weird on the Windows 7 -64 bit platform
// with Visual Studio 2010 that causes the error message:
// "The application was unable to start correctly (0xc000007b)
// This is an experiment to see if the MySQL connector is the culprit.
// m_p_sql_driver = 0;
// When the MySQL Connector C++ is not used, the application starts up
// without the error.
#if (_MSC_VER == 1600)
m_p_sql_driver = 0;
sql::Driver * p_driver = sql::mysql::get_driver_instance();
m_p_sql_driver = p_driver;
// m_p_sql_driver = sql::mysql::get_driver_instance();
#else
m_p_sql_driver = sql::mysql::get_mysql_driver_instance();
#endif
if (m_p_sql_driver)
{
driver_initialized = true;
}
}
}
return;
}
似乎您的VC++在链接过程中没有包含libmysql.lib
,请确保在Linker -> Command Line
中具有类似/LIBPATH:"C:mysqlpathtomysqllib" "libmysql.lib"
的内容。此外,您可以进行一些解决方法,例如
1.在Linker Input Additional Dependancies
:重命名libmysql.lib
为不存在的其他名称,重建,验证是否存在链接错误LINK : fatal error LNK1104: cannot open file 'libmysql.lib'
。这样可以确保link
实际找到库libmysql.lib
2.撤消步骤1中的更改,尝试在VC++ Directories -> Library Directories
中添加libmysql.lib的路径。
希望有帮助。
没错
您必须将"libmysql.lib"添加到链接器输入其他依赖项:项目属性>链接器>输入>其他依赖项。然后在 exe 文件夹(PATH 中定义的文件夹)中复制 libmysql.dll,例如 'c:\windows'
您的问题将得到解决。
您可以在安装 MySQL 的文件夹中找到 libmysql.dll 。
上面告诉了使用"MySQL.h"标头的问题。 如果你想使用连接器++头,那就不一样了。
- C++MySQL C api用户输入行
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 使用mysql c++连接器的未定义引用
- 无法在C++中建立与MySQL数据库的连接
- mysql C++ connector [mysql-connector-c++-8.0.19-linux-glibc2
- C++应用程序 MySQL odbc 数据库连接错误:在引发"otl_tmpl_exception<>"实例后终止调用
- Poco FindMySql.cmake 无法找到 MySQL 源代码
- MySQL C++连接器链接错误
- WinSock2:connect() 提供"连接被拒绝"
- 配置:错误:找不到 MySQL 包含目录
- 在装有 CLion 的 Mac 上使用 C++ 连接到 MySQL 数据库时出现问题
- 如何使用connect将qml按钮与同一类的cpp函数连接起来
- C++MySQL连接器没有utf8
- Qt5 从 MySQL 数据库中选择数据
- 在 QTextEdit 中使用指针或在 Qt-Creator 上使用 connect()
- Arch Linux.AUR 包 mysql 不能用 makepkg 构建.错误:构建 () 中出现故障
- C-Free and MySQL connect
- visual c++ 2010 mysql connect
- VS2013 c++connect mysql--Libmysql.dll中出现错误
- Mysql连接器connect()问题