【问题标题】:Visual Studio 2019 error on build C++ MySQL connector构建 C++ MySQL 连接器时出现 Visual Studio 2019 错误
【发布时间】:2021-08-27 13:51:46
【问题描述】:

我从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 个主题,也在其他网站上阅读了同样的问题,并尝试了他们提供的所有解决方案,但没有一个有效。

我尚未检查的唯一解决方案是下载 VS 2015 并尝试使用它。

现在是 2021 年,这真的是创建 C++/MySQL 简单 APP 的正确解决方案还是我必须做其他事情?

【问题讨论】:

  • 关于 dllimport 的 2 个错误看起来你没有链接到 dll 附带的 .lib 文件(导入库)
  • Visual Studio 2015 到 2019 应该是二进制兼容的,但有一些例外:https://docs.microsoft.com/en-us/cpp/porting/binary-compat-2015-2017?view=msvc-160
  • @drescherjm 我在 vs2019 的附加路径中添加了 x64 lib。这是你的意思还是需要做其他事情?
  • 您还应该在您正在使用的每个配置(调试、发布 ...)中向 Linker->Input->Additional Dependencies 设置添加至少 1 个库。

标签: c++ mysql visual-studio mysql-connector connector


【解决方案1】:

在检查了互联网上的所有解决方案后,最终通过将所有 .dll 文件复制到 c:/windows 解决了问题!

【讨论】:

  • 这很奇怪,因为 dll 根本不参与原生 c++ 应用程序的构建过程。
  • @drescherjm 我同意你的观点,但这是为我解决问题的方法。
猜你喜欢
  • 2021-04-16
  • 1970-01-01
  • 2021-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-14
  • 2018-05-12
  • 1970-01-01
相关资源
最近更新 更多