如何删除警告LNK4217和LNK4049 [英] How to delete warnings LNK4217 and LNK4049

查看:578
本文介绍了如何删除警告LNK4217和LNK4049的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在链接步骤上有警告.这些警告仅在发布模式下出现.

I have warnings on the link step. These warnings appear only in release mode.

我的程序由两部分组成:一个生成.lib的库和一个使用此库的可执行文件.

My program is composed of two parts: a library which generates a .lib and an executable which uses this library.

构建库时,我没有警告.但是,当我生成可执行文件时,在链接上我会显示警告LNK4217和LNK4049.例如:

When I build the library I have no warnings. But when I build my executable, on the link I have warnings LNK4217 and LNK4049. For example:

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)的声明引起的.但是,在我的lib类中,我没有这样声明的东西.例如,这是我的类Exception:

I have read in the MSDN, these warnings may be caused by the declaration of __declspec(dllimport). But, in my classes of my lib, I haven't things declared like this. For example, here is my class 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

有人可以告诉我为什么出现这些警告以及如何删除它们吗?

Can somebody tell me why these warnings appear and how to delete them ?

推荐答案

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

It's caused by __declspec(import) on the symbols mentioned as "imported", ie. on public: __thiscall std::exception::exception(char const * const &). That may be caused by mismatch between compiler option for runtime selection (/MT (static multi-threaded runtime) v.s. /MD (dynamic runtime)) and the preprocessor options (_DLL define). In particular those warnings would appear if you compile with /MT (or /MTd in debug configuration), but _DLL somehow got defined.

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

So make sure you are not defining _DLL when not compiling with /MD.

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

It is also important to compile all libraries for the same runtime as the executable, so check that the runtime selection matches for all projects and that you are linking appropriate version of any third-party libraries.

这篇关于如何删除警告LNK4217和LNK4049的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆