gpt4 book ai didi

c++ - 如何删除警告 LNK4217 和 LNK4049

转载 作者:IT老高 更新时间:2023-10-28 22:12:33 27 4
gpt4 key购买 nike

我在链接步骤上有警告。这些警告仅在 Release模式下出现。

我的程序由两部分组成:一个生成 .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)

我在 MSDN 中阅读过,这些警告可能是由 __declspec(dllimport) 的声明引起的。但是,在我的库中,我没有这样声明。例如,这里是我的类 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

谁能告诉我为什么会出现这些警告以及如何删除它们?

最佳答案

它是由__declspec(import) 在提到的“导入”符号上引起的,即。在 public: __thiscall std::exception::exception(char const * const &)。这可能是由于运行时选择的编译器选项(/MT(静态多线程运行时)与 /MD(动态运行时))和预处理器选项(_DLL 定义)。特别是如果您使用 /MT(或调试配置中的 /MTd)编译,则会出现这些警告,但 _DLL 以某种方式被定义。

因此,请确保在不使用 /MD 进行编译时未定义 _DLL

为与可执行文件相同的运行时编译所有库也很重要,因此请检查所有项目的运行时选择是否匹配,并且您正在链接任何第三方库的适当版本。

关于c++ - 如何删除警告 LNK4217 和 LNK4049,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6979491/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com