简体   繁体   English

C ++ MySQL Linker错误

[英]C++ MySQL Linker errors

I am new to Visual C++. 我是Visual C ++的新手。 I wanted to work with MySQL/C++. 我想使用MySQL / C ++。 So, I 所以我

  • Installed MySQL on my machine Installed VS 2010 Professional on my machine 在计算机上安装MySQL在计算机上安装VS 2010 Professional
  • From the internet, I found that My SQL drivers are found in 从互联网上,我发现My SQL驱动程序位于

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

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

  • I made a sample program, which I copied from this . 我制备的样品程序,这是我从复制
  • Build the project 建立项目
  • Got errors related to boost 得到与升压有关的错误
  • Downloaded Boost from Download boost_1_61_0.7z (74.8 MB) 下载的boost_1_61_0.7z下载的Boost (74.8 MB)
  • Unzipped the archive 解压缩档案
  • Added Include path using Project Properties > C/C++ > General > Additional Include Directories 使用项目属性> C / C ++>常规>其他包含目录添加了包含路径

在此处输入图片说明

  • Added Linker additional libraries using Project Properties > Linker > General > Additional Library Directories 使用项目属性>链接器>常规>其他库目录添加了Linker其他库

在此处输入图片说明

  • Built the Project 建立项目
  • Now it fails with below errors 现在它失败并出现以下错误

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:错误LNK2019:无法解析的外部符号“ __declspec(dllimport)public:class std :: basic_string,class std :: allocator> const&__thiscall sql :: SQLException :: getSQLState(void)const”((__imp_?getSQLState函数__catch $ _wmain $ 0中引用的@ SQLException @ sql @@ QBEABV?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ XZ)

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:错误LNK2019:未解析的外部符号“ __declspec(dllimport)公共: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 : 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:错误LNK2019:未解析的外部符号“ __declspec(dllimport)公共:__thiscall sql :: SQLString :: SQLString(char const * const)”(__imp _ ?? 0SQLString @ sql @@ QAE @ QBD @ Z)在函数_wmain中

1>DemoDB.obj : error LNK2019: unresolved external symbol __imp__get_driver_instance referenced in function _wmain 1> DemoDB.obj:错误LNK2019:函数_wmain中引用的未解析的外部符号__imp__get_driver_instance

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) 1> DemoDB.obj:错误LNK2019:无法解析的外部符号“ __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)在函数“ 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)

在此处输入图片说明

Please help. 请帮忙。 I am totally stuck 我完全被困住了

Edit: 编辑:

This line is causing below error 该行导致以下错误

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 1> DemoDB.obj:错误LNK2019:无法解析的外部符号“ __declspec(dllimport)public:class std :: basic_string,class std :: allocator> const&__thiscall sql :: SQLException :: getSQLState(void)const”((__imp_?getSQLState函数__catch $ _wmain $ 0中引用的@ SQLException @ sql @@ QBEABV?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ XZ)

I have referred below so far, but no help 到目前为止,我已经在下面提到了,但没有帮助

I managed to solve this, after a lot of struggle. 经过很多努力,我设法解决了这个问题。 Below is what helped me 以下是对我有帮助的

  • First, went to Project Properties > Configuration Manager > "Created new configuration for Platform x64 , as my MySQL library was 64-bit 首先,转到“ 项目属性”>“配置管理器”>“为Platform x64创建新配置 ,因为我的MySQL库是64位的

在此处输入图片说明

  • Second, went to Project Properties > C/C++ > General > Additional Include Directories and included path for MySQL C++ Connector & MySQL Connector C 其次,转到“ 项目属性”>“ C / C ++”>“常规”>“其他包含目录”“ MySQL C ++连接器和MySQL连接器C的包含路径”

在此处输入图片说明

  • Third, went to Project Properties > Linker > General > Additional Libraries Directories and added path for MySQL C++ connector 第三,转到项目属性>链接器>常规>其他库目录,添加MySQL C ++连接器的路径

在此处输入图片说明

  • Fourth, went to Project Properties > Linker > Input > Additional Dependencies and added mysqlcppcon.lib 第四,转到“ 项目属性”>“链接器”>“输入”>“其他依赖项”,添加了mysqlcppcon.lib

在此处输入图片说明

After all this, built the project and it ran fine ! 毕竟,构建了项目并运行良好! :) :)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM