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

I am getting an error when migrating my application from VC6 to Visual Studio 2005.

Does anyone know what this means?

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

+1


source to share


3 answers


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

Error LNK2005 occurs when CRT and MFC libraries are in the wrong order in Visual C ++

Insofar as

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

So,



There are two ways to solve 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 fix it.

Or

Force linker to link Libraries in the correct order

  • From the Project menu, choose Settings.
  • In the Options window To view the Project Options dialog box, click select the project configuration that is receiving link errors.
  • On the Link tab, select Enter in the Category field.
  • In the Ignore Libraries field, paste the library names (for example, Nafxcwd.lib; Libcmtd.lib).

    Note. Linker command line component at / NOD :.

  • In the Object / Library field, insert the names of the libraries. You need to make sure they are listed in order and as the first two libraries on a line (eg Nafxcwd.lib Libcmtd.lib).

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

or

Find and fix the Problematic module View the current link order in the library by following these steps:

  • From the Project menu, choose Settings.
  • In the Options window To view the Project Options dialog box, click select the project configuration that is receiving link errors.
  • On the Communication tab, enter / verbose: lib in the Project Options box.
  • Rebuild your project. Libraries will be listed on the window exit during the linking process.
+2


source


I'm sure this can happen for a variety of reasons: the worst one I've ever found is trying to integrate multiple static libraries (ours) that were originally DLLS (we actually build projects as DLLs and static libraries) ...

Our C ++ / CLI library used static versions of these libraries (To avoid DLL dependency issues causing ASP.NET loading issues when using C ++ / CLI Dlls) and initially saw the same linker error.

The problem was using the AFX_MANAGE_STATE (AfxGetStaticModuleState ()) macro, which was needed when the code was built as a DLL, but not actually needed to call the static library.



To solve this problem, I added 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 I eventually figured out what it was by enabling the / VERBOSE option for the linker and seeing the who, what, where and when it pulls in the runtime libraries. (Project Properties / Configuration Properties / Connector / Show progress in vs2005)

+2


source


You can set the linker input to ignore the problematic library in the project properties, but this may or may not work.

0


source







All Articles