如何避免“已定义的错误”在C ++中 [英] how to avoid "already defined error" in C++

查看:132
本文介绍了如何避免“已定义的错误”在C ++中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MFC VS6项目中得到这些类型的错误,同时链接应用程序:

  msvcrt.lib(MSVCRT。 dll):错误LNK2005:_atoi已在LIBC.lib(atox.obj)中定义

它意味着(一个函数存在于2个不同的库);要解决它,我应该排除2个库之一( msvcrt.lib libc.lib )。 / p>

但是如果我这样做有各种未解决的外部错误。所以我想继续使用这两个库。



有什么方法告诉链接器,我想使用 _atoi cvc> 中的<$ c> c>函数,而不是 msvcrt.lib

解决方案

似乎有一个选项,您可以使用它来忽略这样的错误:在项目设置>链接>选中强制文件输出。这将产生程序,即使有linkerrors。



Build输出给出如下:



msvcrt .lib(MSVCRT.dll):警告LNK4006:_atoi已在LIBC.lib(atox.obj)中定义;第二个定义被忽略



当然,你需要小心使用这个选项,因为它可以生成一个应用程序,在某些情况下不工作,但在这里它可能不' (我希望)。



感谢其他回复,但这在我的特殊情况下似乎不是一个选项。


I am gettings these type of errors in a MFC VS6 project while linking the application:

msvcrt.lib(MSVCRT.dll) : error LNK2005: _atoi already defined in LIBC.lib(atox.obj)

I know what it means (a function exists in 2 different libraries); to solve it I should have to exclude one of the 2 libraries (msvcrt.lib or libc.lib).

But if I do this there are all kinds of unresolved external errors. So I would like to keep using both libraries.

Is there any way to tell the linker that I want to use the _atoi function in libc.lib and not in msvcrt.lib (or the other way around)?

Any help or direction would be great.

解决方案

There seems to be an option which you can use to ignore errors like this: in projectsettings > link > check 'Force file output'. This will generate the program even if there are linkerrors.

The Build output gives something like this:

msvcrt.lib(MSVCRT.dll) : warning LNK4006: _atoi already defined in LIBC.lib(atox.obj); second definition ignored

Of course you will need to use this option with care as it can generate an application which won't work in some cases, but here it probably doesn't do any harm (I hope).

Thank you for the other replies, but that didn't seem to be an option in my particular case.

这篇关于如何避免“已定义的错误”在C ++中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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