Visual Studio 构建 C++ MySQL 连接器时出现 2019 错误
Visual Studio 2019 error on build C++ MySQL connector
我从 Connector/C++ 8.0.26 下载了库和头文件,并一一尝试,但总是在构建点上出错。
我使用 Visual Studio 2019(版本 16.10.0)并根据 MySQL 网站的示例创建了一个简单的控制台应用程序。原来的例子是这样的:
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
using namespace std;
int main(void)
{
cout << endl;
cout << "Running 'SELECT 'Hello World!' »
AS _message'..." << endl;
try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
/* Connect to the MySQL test database */
con->setSchema("test");
stmt = con->createStatement();
res = stmt->executeQuery("SELECT 'Hello World!' AS _message");
while (res->next()) {
cout << "\t... MySQL replies: ";
/* Access column data by alias or column name */
cout << res->getString("_message") << endl;
cout << "\t... MySQL says it again: ";
/* Access column data by numeric offset, 1 is the first column */
cout << res->getString(1) << endl;
}
delete res;
delete stmt;
delete con;
} catch (sql::SQLException &e) {
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line " »
<< __LINE__ << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
cout << endl;
return EXIT_SUCCESS;
}
我在不同的配置下遇到了同样的错误(32,64,Debug|release ....):
我在这里阅读了超过 100 个主题,在其他网站上也阅读了关于相同问题的主题,并尝试了他们提供的每一个解决方案,但 none 其中有效。
我尚未检查的唯一解决方案是下载 VS 2015 并尝试使用它。
现在是 2021 年,这真的是创建 C++/MySQL 简单 APP 的正确解决方案,还是我必须做其他事情?
在检查了互联网上的所有解决方案后,最终通过将所有 .dll
文件复制到 c:/windows
解决了问题!
我从 Connector/C++ 8.0.26 下载了库和头文件,并一一尝试,但总是在构建点上出错。
我使用 Visual Studio 2019(版本 16.10.0)并根据 MySQL 网站的示例创建了一个简单的控制台应用程序。原来的例子是这样的:
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
using namespace std;
int main(void)
{
cout << endl;
cout << "Running 'SELECT 'Hello World!' »
AS _message'..." << endl;
try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
/* Connect to the MySQL test database */
con->setSchema("test");
stmt = con->createStatement();
res = stmt->executeQuery("SELECT 'Hello World!' AS _message");
while (res->next()) {
cout << "\t... MySQL replies: ";
/* Access column data by alias or column name */
cout << res->getString("_message") << endl;
cout << "\t... MySQL says it again: ";
/* Access column data by numeric offset, 1 is the first column */
cout << res->getString(1) << endl;
}
delete res;
delete stmt;
delete con;
} catch (sql::SQLException &e) {
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line " »
<< __LINE__ << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
cout << endl;
return EXIT_SUCCESS;
}
我在不同的配置下遇到了同样的错误(32,64,Debug|release ....):
我在这里阅读了超过 100 个主题,在其他网站上也阅读了关于相同问题的主题,并尝试了他们提供的每一个解决方案,但 none 其中有效。
我尚未检查的唯一解决方案是下载 VS 2015 并尝试使用它。
现在是 2021 年,这真的是创建 C++/MySQL 简单 APP 的正确解决方案,还是我必须做其他事情?
在检查了互联网上的所有解决方案后,最终通过将所有 .dll
文件复制到 c:/windows
解决了问题!