我正在尝试运行 MongoDB C++ 驱动程序的示例程序,以便我可以运行一些测试,并且遇到了一些我坚持的错误。
Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall mongo::DBClientConnection::DBClientConnection(bool,class mongo::DBClientReplicaSet *,double)" (__imp_??0DBClientConnection@mongo@@QAE@_NPAVDBClientReplicaSet@1@N@Z) referenced in function "void __cdecl run(void)" (?run@@YAXXZ) E:\Programming\C++\BoostTest\BoostTest\BoostTest\Testcpp.obj BoostTest
Error 2 error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall mongo::DBClientConnection::~DBClientConnection(void)" (__imp_??1DBClientConnection@mongo@@UAE@XZ) referenced in function "void __cdecl run(void)" (?run@@YAXXZ) E:\Programming\C++\BoostTest\BoostTest\BoostTest\Testcpp.obj BoostTest
Error 3 error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall mongo::DBClientConnection::connect(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_?connect@DBClientConnection@mongo@@QAEXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "void __cdecl run(void)" (?run@@YAXXZ) E:\Programming\C++\BoostTest\BoostTest\BoostTest\Testcpp.obj BoostTest
这是代码
#include <cstdlib>
#include <iostream>
#include "mongo\client\dbclient.h"
#define BOOST_ALL_DYN_LINK
void run()
{
mongo::DBClientConnection c;
c.connect("localhost");
}
int main()
{
try
{
run();
std::cout << "Connected" << std::endl;
}
catch(const mongo::DBException &e)
{
std::cout << "caught " << e.what() << std::endl;
}
return EXIT_SUCCESS;
}
在有人问之前,我已经引用了 Boost 库和标题,它们似乎工作正常。我还参考了 Mongo 库和标题。
Additional Include Directories: Boost and Mongo Source
Linker Additional Library Directories: boost/stage/lib and Mongo build client
有人有任何线索吗?我是否必须在附加依赖项中包含 dbclient.obj 文件?当我这样做时,我会收到 96 个新错误。我想我可能遗漏了一些 .dll 但不知道是什么。
将不胜感激任何帮助,因为这只是一个更大的项目的一小部分。