XLL+ Class Library

Linker Error LNK2005

After saving a project, the linker fails with error LNK2005

Symptoms

After adding a new source file or library to an XLL+ project and saving the project, the following linker error occurs:

LNK2005: symbol multiply defined
In particular, this can occur in a project which previously linked perfectly.

Summary

  1. The Microsoft run-time libraries use weak external linkage to resolve the linking of some important functions, including new, delete and DllMain().
    Optionally, see MSDN articles Q148652 and Q72651 for more details of this technique and its implications, in order to gain a deeper understanding of what is occurring.
  2. To be sure of curing the problem, instruct the linker to Ignore all default libraries (/NOD) and enter a complete list of libraries required for the build.
    A full list of the libraries required for the various builds is below.

Procedure for fixing the problem

In the Link tab of the Project Settings dialog, select the Input category, and check the field Ignore all default libraries, as shown below. Note that you will need to do this for both builds, Debug and Release.

In the Object/library modules field add the required libraries at the beginning (i.e. left-hand side) of the list. The required libraries are as follows. Ensure that you select the correct libraries for the builds you are using.

Build Libraries
MFC Debug xlllibd.lib mfc42d.lib mfcs42d.lib msvcrtd.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib advapi32.lib shell32.lib comctl32.lib uuid.lib mfco42d.lib oledlg.lib ole32.lib olepro32.lib oleaut32.lib urlmon.lib mfcd42d.lib msvcprtd.lib oldnames.lib version.lib
MFC Release xlllibr.lib mfc42.lib mfcs42.lib msvcrt.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib advapi32.lib shell32.lib comctl32.lib uuid.lib oledlg.lib ole32.lib olepro32.lib oleaut32.lib urlmon.lib msvcprt.lib oldnames.lib version.lib
STL Debug xlllibsd.lib uuid.lib libcpmtd.lib libcmtd.lib oldnames.lib kernel32.lib version.lib
STL Release xlllibsr.lib uuid.lib libcpmt.lib libcmt.lib oldnames.lib kernel32.lib version.lib