C++ – Linker error after porting C++ application from VC6 to VS2005

mfcvisual c++visual-c++-6visual-studio-2005

I am getting an error while porting my application from VC6 to Visual Studio 2005.

Does anyone have any idea what this means?

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

Best Answer

From http://support.microsoft.com/default.aspx?scid=kb;en-us;q148652

A LNK2005 error occurs when the CRT library and MFC libraries are linked in the wrong order in Visual C++

Because

The CRT libraries use weak external linkage for the new, delete, and DllMain functions. The MFC libraries also contain new, delete, and DllMain functions. These functions require the MFC libraries to be linked before the CRT library is linked.

So

There are two ways to resolve this problem. The first solution involves forcing the linker to link the libraries in the correct order. The second solution allows you to find the module that is causing the problem and to correct it.

Either

Force Linker to Link Libraries in Correct Order

  1. On the Project menu, click Settings.
  2. In the Settings For view of the Project Settings dialog box, click to select the project configuration that is getting the link errors.
  3. On the Link tab, click to select Input in the Category combo box.
  4. In the Ignore libraries box, insert the library names (for example, Nafxcwd.lib;Libcmtd.lib).

    Note The linker command-line equivalent in /NOD:.

  5. In the Object/library modules box, insert the library names. You must make sure that these are listed in order and as the first two libraries in the line (for example, Nafxcwd.lib Libcmtd.lib).

To set this option in Visual C++ .NET, read the "Setting Visual C++ Project Properties" online help topic.

Or

Locate and Correct the Problem Module To view the current library link order, follow these steps:

  1. On the Project menu, click Settings.
  2. In the Settings For view of the Project Settings dialog box, click to select the project configuration that is getting the link errors.
  3. On the Link tab, type /verbose:lib in the Project Options box.
  4. Rebuild your project. The libraries will be listed in the output window during the linking process.
Related Topic