Search code examples
c++visual-c++linker

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


I am getting this linker error.

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

Please tell me the correct way of eliminating this bug. I read solution on microsoft support site about this bug but it didnt helped much.

I am using VS 2005 with Platform SDK


Solution

  • 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)