Ced*_*sme 17 c++ warnings visual-studio-2010 visual-studio
我在链接步骤上有警告.这些警告仅在发布模式下出现.
我的程序由两部分组成:一个生成.lib的库和一个使用该库的可执行文件.
当我建立图书馆时,我没有任何警告.但是当我构建我的可执行文件时,在链接上我发出警告LNK4217和LNK4049.例如:
3>DaemonCommon.lib(Exception.obj) : warning LNK4217: locally defined symbol ??0exception@std@@QAE@ABQBD@Z (public: __thiscall std::exception::exception(char const * const &)) imported in function "public: __thiscall std::bad_alloc::bad_alloc(char const *)" (??0bad_alloc@std@@QAE@PBD@Z)
3>DaemonCommon.lib(CommAnetoException.obj) : warning LNK4217: locally defined symbol ??0exception@std@@QAE@ABQBD@Z (public: __thiscall std::exception::exception(char const * const &)) imported in function "public: __thiscall std::bad_alloc::bad_alloc(char const *)" (??0bad_alloc@std@@QAE@PBD@Z)
Run Code Online (Sandbox Code Playgroud)
我在MSDN中读过,这些警告可能是由__declspec(dllimport)的声明引起的.但是,在我的lib类中,我没有像这样声明的东西.例如,这是我的类Exception:
#ifndef _EXCEPTION_HPP__
#define _EXCEPTION_HPP__
#include <string>
namespace Exception
{
class Exception
{
public:
// Constructor by default
Exception();
// Constructor parametrized
Exception(std::string& strMessage);
// Get the message of the exception
virtual std::string getMessage() const;
// Destructor
virtual ~Exception();
protected:
// String containing the message of the exception
std::string mStrMessage;
};
}
#endif
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我为什么会出现这些警告以及如何删除它们?
Jan*_*dec 22
它是由__declspec(import) 提到的"导入"符号引起的,即.在public: __thiscall std::exception::exception(char const * const &).这可能是由运行时选择的编译器选项(/MT(静态多线程运行时)与/MD(动态运行时))和预处理器选项(_DLL定义)之间的不匹配引起的.特别是如果使用/MT(或/MTd在调试配置中)编译,那么会出现这些警告,但_DLL不知何故已定义.
因此,请确保_DLL在未编译时未定义/MD.
编译与可执行文件相同的运行时的所有库也很重要,因此请检查运行时选择是否与所有项目匹配,以及是否链接了任何第三方库的相应版本.
| 归档时间: |
|
| 查看次数: |
25082 次 |
| 最近记录: |