gpt4 book ai didi

c++ - 错误 LNK2005 : "void __cdecl operator delete(void *)" (? ?3@YAXPAX@Z) 已在 LIBCMTD.lib(delete_scalar.obj) 中定义

转载 作者:行者123 更新时间:2023-12-03 06:55:01 25 4
gpt4 key购买 nike

我编写了一个覆盖删除操作符的 c++ 静态库。
在测试项目中使用库时,项目产生如下错误:

错误 LNK2005:“void __cdecl operator delete(void *)” (??3@YAXPAX@Z) 已在 LIBCMTD.lib(delete_scalar.obj) 中定义

搜索了答案后,我相信这是由于 CRT 和 MFC 库的包含顺序造成的,但是在尝试应用解决方案时,所有答案都过时了。我正在使用 Visual Studio 2017。

谁能告诉我如何正确构建我的库?谢谢。

编辑 - 我知道一个定义规则。我试图找出如何防止包含 LIBCMTD.lib 版本。

最佳答案

看看这里:

https://docs.microsoft.com/en-gb/cpp/error-messages/tool-errors/linker-tools-error-lnk2005

正如您将在文章中看到的,有几个原因。例如:

This error can occur if you link more than one version of the standard library or CRT. For example, if you attempt to link both the retail and debug CRT libraries, or both the static and dynamic versions of a library, or two different versions of a standard library to your executable, this error may be reported many times. To fix this issue, remove all but one copy of each library from the link command. We do not recommend you mix retail and debug libraries, or different versions of a library, in the same executable.

To tell the linker to use libraries other than the defaults, on the command line, specify the libraries to use, and use the /NODEFAULTLIB option to disable the default libraries. In the IDE, add references to your project to specify the libraries to use, and then open the Property Pages dialog for your project, and in the Linker, Input property page, set either Ignore All Default Libraries, or Ignore Specific Default Libraries properties to disable the default libraries.



过去我不得不这样做。

关于c++ - 错误 LNK2005 : "void __cdecl operator delete(void *)" (? ?3@YAXPAX@Z) 已在 LIBCMTD.lib(delete_scalar.obj) 中定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46638252/

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