PRB: When building a project, the linker fails with error LNK2005

Reference: Q0004

Article last modified on 28-Nov-2005


The information in this article applies to:

  • XLL+ for Visual Studio .NET - 3, 4.1, 4.2, 4.3.1
  • XLL+ for Visual Studio 6 - 3, 4.1, 4.2, 4.3.1
  • Excel - all versions

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. The simplest way to fix the problem under Visual Studio.NET and under Visual Studio.NET 2003 is to add the appropriate XLL+ library to the start of the linker's list of Additional Dependencies.

    A list of the appropriate libraries is below.

  3. To be sure of curing the problem under Visual Studio 6, 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 Visual Studio.NET and Visual Studio.NET 2003

  1. Open the Project Property Pages. (You can do this via the Project - <YourApp> Properties menu in Visual Studio .NET.)
  2. Select the node Configuration Properties/Linker/Input.
  3. In the Additional Dependencies field, add the XLL+ library name at the start of the list.

    The library names for the various builds are listed below. Please note the spelling carefully.

Build Library
STL Release xlllibsr.lib
STL Debug xlllibsd.lib
MFC Release xlllibr.lib
MFC Debug xlllibd.lib

Procedure for fixing the problem in Visual Studio 6

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