我收到错误
mongoclient.lib(assert_util.obj) : error LNK2005: void __cdecl mongo::uasserted(...) already defined in someOwnFile.obj
在链接时,以及mongo::msgasserted
和mongo::msgasserted
。
在someOwnFile.cpp
,我有
#include <string>
#ifdef WIN32
// Needed for mongo BSON.
#pragma warning(push)
#pragma warning(disable: 4800)
#pragma warning(disable: 4244)
#pragma warning(disable: 4267)
#define _CRT_SECURE_NO_WARNINGS 1
#endif
#include <mongo/bson/bson.h>
#ifdef WIN32
#pragma warning(pop)
#endif
// ...
为什么我会收到错误?我该如何解决?
答案 0 :(得分:0)
在包含此文件时似乎存在问题。
现在我正在这样做:
#ifdef WIN32
// Mongo uses boost.filesystem. Include it here to force to link it in (via its pragma lib).
#include <boost/filesystem.hpp>
// Needed for mongo BSON.
#pragma warning(push)
#pragma warning(disable: 4800)
#pragma warning(disable: 4244)
#pragma warning(disable: 4267)
#define _CRT_SECURE_NO_WARNINGS 1
#endif
#include <mongo/client/dbclient.h>
#include <mongo/client/dbclient_rs.h>
#include <mongo/client/gridfs.h>
#ifdef WIN32
#pragma warning(pop)
#endif
这很有效。