【问题标题】:C++ MySQL Linker errorsC++ MySQL 链接器错误
【发布时间】:2016-12-07 22:42:10
【问题描述】:

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

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

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

C:\Program Files\MySQL\Connector.C++ 1.1\lib

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

  • 使用项目属性>链接器>常规>附加库目录添加了链接器附加库

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

1>DemoDB.obj:错误 LNK2019:未解析的外部符号 "__declspec(dllimport) 公共:类 std::basic_string,类 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) 在函数 __catch$_wmain$0 中引用

1>DemoDB.obj:错误 LNK2019: 未解析的外部符号“__declspec(dllimport) public: int __thiscall sql::SQLException::getErrorCode(void)const " (__imp_?getErrorCode@SQLException@sql@@QBEHXZ) 在函数中引用 __catch$_wmain$0 1>DemoDB.obj:错误 LNK2019:无法解析的外部符号“__declspec(dllimport) public: __thiscall sql::SQLString::~SQLString(void)" (__imp_??1SQLString@sql@@QAE@XZ) 在函数 _wmain 中引用

1>DemoDB.obj:错误 LNK2019:未解决 外部符号“__declspec(dllimport) public: __thiscall sql::SQLString::SQLString(char const * const)" (__imp_??0SQLString@sql@@QAE@QBD@Z) 在函数_wmain中引用

1>DemoDB.obj:错误 LNK2019:未解析的外部符号 __imp__get_driver_instance 在函数 _wmain 中引用

1>DemoDB.obj:错误 LNK2019:无法解析的外部符号“__declspec(dllimport) 公共:类 std::basic_string,类 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) 在函数“class std::basic_ostream > & __cdecl std::operator &,类 sql::SQLString 常量 &)" (??6std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@ABVSQLString@sql@@@Z)

请帮忙。我完全卡住了

编辑:

此行导致以下错误

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

1>DemoDB.obj:错误 LNK2019:未解析的外部符号 "__declspec(dllimport) 公共:类 std::basic_string,类 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) 在函数 __catch$_wmain$0

中引用

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

【问题讨论】:

  • 可能您安装的 MySQL 驱动程序来自不同版本的 Visual Studio。
  • @drescherjm 我从这个链接下载了 MySQL (v5.7.14)。我如何知道 MySQL for Visual Studio 的兼容性?链接 --> cdn.mysql.com//Downloads/MySQLInstaller/…
  • 您使用的 MySQL 库是否使用编译指示自动链接?
  • @drescherjm 我相信它有,因为即使我没有使用#pragma,我的库也被链接了。我解决了这个定义预处理器宏“CPPCONN_PUBLIC_FUNC="
  • 如果这个问题得到解决,您应该发布您的解决方案作为答案。

标签: c++ mysql visual-studio-2010 boost


【解决方案1】:

经过一番努力,我设法解决了这个问题。以下是有帮助的 我

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

  • 其次,转到 Project Properties > C/C++ > General > Additional Include DirectoriesMySQL C++ Connector 和 MySQL Connector C 的包含路径

  • 第三,转到项目属性>链接器>常规>附加库目录为 MySQL C++ 连接器添加路径

  • 第四,转到项目属性>链接器>输入>附加依赖项添加了mysqlcppcon.lib

在这一切之后,构建了项目并且运行良好! :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多