Linker Tools Errors and War ...


Visual C++ Concepts: Building a C/C++ Program
Linker Tools Error LNK2005

Error Message

symbol already defined in object

The given symbol, displayed in its decorated form, was multiply defined.

For more information, see the Knowledge Base articles:

  • "LNK2005 Errors When Link C Run-Time Libraries Are Linked Before MFC Libraries" (Q148652)

  • "Global Overloaded Delete Operator Causes LNK2005" (Q140440)

  • "LNK2005 Errors on New and Delete When Defining _ATL_MIN_CRT" (Q184235).

You can find Knowledge Base articles on the MSDN Library CD-ROM or at http://support.microsoft.com/support.

This error is followed by fatal error LNK1169.

To fix by checking the following possible causes

  1. Mixing static and dynamic libraries when also using /clr.

  2. The symbol is a packaged function (created by compiling with /Gy) and was included in more than one file but was changed between compilations. Recompile all files that include symbol.

  3. The symbol is defined differently in two member objects in different libraries, and both member objects were used.

  4. An absolute is defined twice, with a different value in each definition.

  5. A header file declared and defined a variable. Possible solutions include:

    • Declare the variable in .h: extern BOOL MyBool; and then assign to it in a .c or .cpp file: BOOL MyBool = FALSE;.

    • Declare the variable static.

    • Declare the variable selectany.

  6. If you use uuid.lib in combination with other .lib files that define GUIDs (for example, oledb.lib and adsiid.lib). For example:

    oledb.lib(oledb_i.obj) : error LNK2005: _IID_ITransactionObject
    already defined in uuid.lib(go7.obj)
    

    To fix, add /FORCE:MULTIPLE to the linker command line options, and make sure that uuid.lib is the first library referenced.

Tags :


Community Content

Nikhil J George
error LNK2005: _foo already defined in MSVCRTD.lib(MSVCR80D.dll) libcmtd.lib
I kept getting a slew of errors of the form "error LNK2005: _malloc already defined in MSVCRTD.lib(MSVCR80D.dll) libcmtd.lib". It turns out that some of these functions are defined twice in libcmtd.lib and msvcrtd.lib. The linker links both of them hence causing this problem. I got around this by getting the linker to avoid linking in libcmtd.lib. This can be done by going to the projects properties menu and then going to "Config Properties-> Input -> Ignore Specific Library". See http://support.microsoft.com/kb/94248 for more details about the runtime libraries.
Tags :

cmsalvatore
error LNK2005: _DllMain@12 already defined in dllmain.obj mfcs90ud.lib

When you change the way your project uses the MFC from Use Standard Windows Libraries to Use MFC in a Shared DLL there will be a dllmain.cpp left as part of your project. This file has the following definition:

BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {...}

This causes the message: error LNK2005: _DllMain@12 already defined in dllmain.obj mfcs90ud.lib

To solve this issue, once you have changed your MFC selection in your project options, just remove the file from the project and rebuild.

Tags :

Page view tracker