gpt4 book ai didi

c++ - MySQL C++ 连接器未解析的外部

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:42:02 29 4
gpt4 key购买 nike

我正在尝试使用 Visual Studio 15 2017 构建一个 MySQL C++ 连接器应用程序,使用 MySQL C++ 连接器作为静态库。但是,在仔细按照 https://dev.mysql.com/doc/connector-cpp/en/connector-cpp-apps-windows-visual-studio.html 给出的指示进行操作后,我收到 LNK2001 错误“未解析的外部符号 _get_driver_instance”。

Additional Include Directories (boost include cut-off) Linker Library Path Static Linker Library This is required for reasons described in the link上面的图片显示了我根据上面的链接设置的所需的库设置和其他设置。

我要构建的代码是:

/* Standard C++ includes */
#include <stdlib.h>
#include <iostream>

/*
Include directly the different
headers from cppconn/ and mysql_driver.h + mysql_util.h
(and mysql_connection.h). This will reduce your build time!
*/
#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)
{
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;
}

来自 MySQL 示例脚本。

我尝试解决问题的一些事情:

  • 将项目平台从 Win32 更改为 x64,并将解决方案平台从 x86 更改为 x64(导致错误 LNK2038“检测到‘_MSC_VER’不匹配:值‘1800’与值‘1900’不匹配”)
  • 键入库的完整路径名
  • 从源代码构建连接器/C++(没有用,但不确定我是否做对了)。

我已阅读有关该主题的大多数其他帖子,但解决方案似乎不起作用。有适用于 Windows 的解决方案吗?

最佳答案

将您的路径放在引号中(因为有空格),即

"C:\Program Files\MySQL\Connector C++ 1.1\lib\opt";

"C:\Program Files\MySQL\Connector C++ 1.1\include";...

此外,请确保您在 Linker -> Input 设置部分列出了所有需要的库。

关于c++ - MySQL C++ 连接器未解析的外部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47956347/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com