简体   繁体   English

错误 LNK2005 DllMain 已在 uafxcw.lib(dllmodul.obj) 中定义

[英]Error LNK2005 DllMain already defined in uafxcw.lib(dllmodul.obj)

I have dll project.我有 dll 项目。 I added to my solution other quite big project that I want to use as a lib in my dll.我在我的解决方案中添加了其他相当大的项目,我想在 dll 中将其用作库。 But when I started to use new project from my dll project, I had several linking errors, also like in this question error LNK2005: new and delete already defined in LIBCMTD.lib(new.obj)但是当我开始从我的 dll 项目中使用新项目时,我遇到了几个链接错误,就像这个问题中的错误 LNK2005: new and delete already defined in LIBCMTD.lib(new.obj)

I've put into "Additional dependency" and "ignore specific library" uafxcwd.lib;Libcmtd.lib, and errors about new, delete etc now is gone, but I still got the error about DllMain.我已经放入“附加依赖项”和“忽略特定库”uafxcwd.lib;Libcmtd.lib,关于新、删除等的错误现在已经消失了,但我仍然收到关于 DllMain 的错误。

I've also tried to put我也试过把

extern "C" { int __afxForceUSRDLL; }

line to the cpp with DllMain and got additional error使用 DllMain 连接到 cpp 并得到额外的错误

Error   LNK2005 __afxForceUSRDLL already defined in dllmain.obj 

I'm completely at a loss我完全不知所措

According to the Doc: Linker Tools Error LNK2005根据文档: Linker 工具错误 LNK2005

If two objects define the same symbol, you get exactly this linker error.如果两个对象定义了相同的符号,您就会得到这个 linker 错误。 I suggest you could try to find out which of both libraries you actually need and then tell the linker not to use the other one.我建议您可以尝试找出您实际需要的两个库中的哪一个,然后告诉 linker 不要使用另一个。

And I suggest you should check the the linker order.The MFC libs need get linked first, and then the CRT libs could be linked.我建议你应该检查 linker 命令。MFC 库需要先链接,然后可以链接 CRT 库。

For more details I suggest you could refer to the link: error LNK2005: _DllMain@12 already defined in MSVCRT.lib有关更多详细信息,我建议您可以参考链接: error LNK2005: _DllMain@12 already defined in MSVCRT.lib

I had the exact same problem with a need to use my own DllMain, but it being already defined in a library that I also needed:我在需要使用自己的 DllMain 时遇到了完全相同的问题,但它已经在我还需要的库中定义:

error LNK2005: DllMain already defined in uafxcw.lib(dllmodul.obj)

The fix from @Jeaninez to add来自@Jeaninez 的修复添加

#ifdef _X86_ extern "C" 
  int _afxForceUSRDLL;  
#else 
  extern "C" { int __afxForceUSRDLL; } 
#endif

just before my own DllMain worked perfectly.就在我自己的 DllMain 完美运行之前。 Thanks.谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM