gpt4 book ai didi

C++ MySQL 链接器错误

转载 作者:行者123 更新时间:2023-11-29 04:17:13 25 4
gpt4 key购买 nike

我是 Visual C++ 的新手。我想使用 MySQL/C++。所以,我

  • 在我的机器上安装了 MySQL 在我的机器上安装了 VS 2010 Professional机器
  • 从网上,我发现我的SQL驱动在

C:\Program Files\MySQL\Connector.C++ 1.1\include <-- Headers

C:\Program Files\MySQL\Connector.C++ 1.1\lib <-- Libs

  • 我制作了一个示例程序,我从this 复制了它.
  • 构建项目
  • 遇到与 boost 相关的错误
  • Download boost_1_61_0.7z (74.8 MB) 下载了 Boost
  • 解压缩文件
  • 使用 Project Properties > C/C++ > General > Additional Include Directories 添加了包含路径

enter image description here

  • 使用 Project Properties > Linker > General > Additional Library Directories 添加了 Linker 附加库

enter image description here

  • 构建项目
  • 现在失败并出现以下错误

1>DemoDB.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_string,class std::allocator > const & __thiscall sql::SQLException::getSQLState(void)const " (__imp_?getSQLState@SQLException@sql@@QBEABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function __catch$_wmain$0

1>DemoDB.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall sql::SQLException::getErrorCode(void)const " (__imp_?getErrorCode@SQLException@sql@@QBEHXZ) referenced in function __catch$_wmain$0 1>DemoDB.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sql::SQLString::~SQLString(void)" (__imp_??1SQLString@sql@@QAE@XZ) referenced in function _wmain

1>DemoDB.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sql::SQLString::SQLString(char const * const)" (__imp_??0SQLString@sql@@QAE@QBD@Z) referenced in function _wmain

1>DemoDB.obj : error LNK2019: unresolved external symbol __imp__get_driver_instance referenced in function _wmain

1>DemoDB.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_string,class std::allocator > const & __thiscall sql::SQLString::asStdString(void)const " (__imp_?asStdString@SQLString@sql@@QBEABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function "class std::basic_ostream > & __cdecl std::operator<<(class std::basic_ostream > &,class sql::SQLString const &)" (??6std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@ABVSQLString@sql@@@Z)

enter image description here

请帮忙。我完全卡住了

编辑:

此行导致以下错误

cout << ", SQLState: " << e.getSQLState() << " )" << endl;

1>DemoDB.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_string,class std::allocator > const & __thiscall sql::SQLException::getSQLState(void)const " (__imp_?getSQLState@SQLException@sql@@QBEABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function __catch$_wmain$0

到目前为止,我在下面提到过,但没有帮助

最佳答案

I managed to solve this, after a lot of struggle. Below is what helped me

  • 首先,转到项目属性 > 配置管理器 >“为平台 x64 创建新配置,因为我的 MySQL 库是 64 位

enter image description here

  • 其次,转到项目属性 > C/C++ > 常规 > 其他包含目录MySQL C++ 连接器和 MySQL 连接器 C 的包含路径

enter image description here

  • 第三,转到Project Properties > Linker > General > Additional Libraries Directories为 MySQL C++ 连接器添加路径

enter image description here

  • 第四,转到Project Properties > Linker > Input > Additional Dependencies添加mysqlcppcon.lib

enter image description here

完成所有这些后,构建项目并且运行良好! :)

enter image description here

关于C++ MySQL 链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38722769/

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