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

前端 未结 17 2054
臣服心动
臣服心动 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 07:18

    For all those who are experiencing this error in ATL projects (mostly when trying to add MFC support), here's the solution I found after days of frustration!

    First of all, this link was more helpful to me than all the others. It pointed me into the right direction. The problem occurs, if the "generated files" (containing the proxy and stub code, just as the type guids) for some reason have been removed and readded to the project. This causes Visual Studio to add them in the wrong order!

    Usually you first come up with the "ATL requires C++ compilation" error, but you may have fixed this by turning out the Yc/Yu (precompiled headers) setting for that file.

    What you should do next is unloading your project and edit it. Search for the item groups that define the build and include order (ClCompile and ClInclude). Check their order and settings.

    The compiles should appear in this order:

    1. dllmain.cpp (with CompileAsManaged set to false and PrecompiledHeader left empty).
    2. Library source (MyLib.cpp, containing DllCanUnloadNow and so on)
    3. Proxy/Stub code (MyLib_i.c; with same settings as dllmain.cpp)
    4. stdafx.cpp (with PrecompiledHeader set to Create)
    5. All the other library source files (your actual libraries content)
    6. xdlldata.c (with the same settings as dllmain.cpp)

    The includes should then be ordered like this:

    1. dllmain.h
    2. MyLib_i.h
    3. Resource.h
    4. stdafx.h
    5. targetver.h
    6. ... (actual library headers)
    7. xdlldata.h

    Fixing the build order fixed my project and I was able to create a new clean build.

提交回复
热议问题