views:

726

answers:

5

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)

A: 

Let me google that for you and it seems several people have asked the same question on other forums, with some useful advice about conflicts etc.

adam
+2  A: 

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.
Adam Davis
A: 

please any one help on this as i am not cleard witht the answers

vijay.j
A: 

please any one help regarding this as i am not able to solve it by any means

vijay.j
+1  A: 

I'm sure there are a number of reason this could happen - the worst one I ever found was when trying to integrate a number of static libraries (ours) that were originally DLLS (in fact, we build the projects as both DLL & static libraries).

Our C++/CLI DLL was using the static versions of these libraries (To avoid DLL dependency issues that were causing ASP.NET loading issues when the C++/CLI Dll was being used) and was initially seeing the same linker error.

The problem turned out to be the use of AFX_MANAGE_STATE(AfxGetStaticModuleState()) macro that was needed when the code was built as a DLL but not actually needed for the static library call.

To solve this i ended up adding the following code to the stdafx.h of each project.

#ifdef OMUTILITIES_LINK_STATIC
    #undef AfxGetStaticModuleState
    #define AfxGetStaticModuleState AfxGetModuleState
#endif

This, of course, may not be your specific problem. But the way i eventually figured it was by turning on the /VERBOSE option for the linker and seeing who, what, where & when it was pulling in the runtime libraries. (Project Properties/Configuration Properties/Linker/Show Progress in vs2005)

Ruddy