error LNK2005: _DllMain@12 already defined in MSVCRT.lib

前端 未结 17 1924
臣服心动
臣服心动 2020-12-14 06:44

I am getting this linker error.

mfcs80.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in MSVCRT.lib(dllmain.obj)

相关标签:
17条回答
  • 2020-12-14 06:52

    MSDN knowledge base ID Q148652.

    http://support.microsoft.com/kb/148652

    Cause: Visual C++ compiles the source files in alphabetical order, and passes the compiled object files to the linker in alphabetical order. If the linker processes DLLDATAX.OBJ first, the source code references DllMain, which the linker loads from MSVCRTD.LIB(dllmain.obj). The linker then processes an object file compiled from a C++ file that contains #include "stdafx.h", which references the symbol __afxForceUSRDLL, which the linker loads from MFC42D.LIB(dllmodul.obj). This object module also contains an implementation for DllMain, causing the conflict.

    0 讨论(0)
  • 2020-12-14 06:53

    I found solution Here Visual Studio 2010 library linking order

    this is: /FORCE:MULTIPLE in linker options

    I had to mix ATL and MFC together , to use [module(name = "mymodule")]; construction in MFC application together with "__hook" keyword

    0 讨论(0)
  • 2020-12-14 06:55

    There is a common theme running through some of the answers here.

    Avishek Bose:-

    Declare the mfc80ud.lib and mfcs80ud.lib in the Additional Dependancies field in the Project Properties -> Linker Tab -> Input of Visual Studio to fix the issue.

    vmb100:-

    I am working with Visual Studio 2010, so in my case the MFC lib is called mfc100.lib.

    joseAndresGomezTovar:-

    I have a very similar problem. [mfcs110d.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in MSVCRTD.lib(dllmain.obj)] and the solution was add mfcs110d.lib to Additional Dependencies

    So the general case seems to be to first find the name of the library to add ...

    and then to add it ....

    Note that there seem to be some prerequisites and/or alternative solutions.

    0 讨论(0)
  • 2020-12-14 07:04

    In my project I was able to solve this problem by adding mfcs80.lib and msvcrt.lib as additional dependencies in the project settings. The 'additional dependencies' can be found under Linker -> Input.

    In the debug configuration that would have to be mfcs80d.lib and msvcrtd.lib respectively.

    By the way, I am working with Visual Studio 2010, so in my case the MFC lib is called mfc100.lib.

    I am not sure why this worked. It is not necessary to add these lib files as additional dependencies because I already set 'Use of MFC' to 'Use MFC in a shared dll'. I guess that by specifying these libraries as additional dependencies they are linked in a different order.

    This solution is more or less the same as the one suggested on the Microsoft site: http://support.microsoft.com/kb/148652, except I did not need to type anything in the 'Ignore specific default libraries' box.

    0 讨论(0)
  • 2020-12-14 07:04

    I have a very similar problem. [mfcs110d.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in MSVCRTD.lib(dllmain.obj)] and the solution was add mfcs110d.lib to Additional Dependencies

    0 讨论(0)
  • 2020-12-14 07:07

    If you read the linker error thoroughly, and apply some knowledge, you may get there yourself:

    The linker links a number of compiled objects and libraries together to get a binary.

    Each object/library describes

    • what symbols it expects to be present in other objects
    • what symbols it defines

    If two objects define the same symbol, you get exactly this linker error. In your case, both mfcs80.lib and MSVCRT.lib define the _DllMain@12 symbol.

    Getting rid of the error:

    1. find out which of both libraries you actually need
    2. find out how to tell the linker not to use the other one (using e.g. the tip from James Hopkin)
    0 讨论(0)
提交回复
热议问题