Solved

LNK2005 error

Posted on 2001-11-02
909 Views
Last Modified: 2013-12-03
Another link error:

nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj)
nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in LIBCMTD.lib(dbgdel.obj)
.\Debug\foo.exe : fatal error LNK1169: one or more multiply defined symbols found

So LIBCMTD.lib is a standard C runtime library, multithreaded and Nafxcwd.lib is afx, debug version

I have the /MTd option in Project Setting -> C/C++

Suggested solutions to this problem that I've seen elsewhere on the net involve changing options on the Project Settings "Link" tab, which I have do not have

Using VC++6

0
Question by:omom
    20 Comments
     
    LVL 11

    Expert Comment

    by:alexo
    What tabs do you have?  Are you using an external makefile?
    0
     

    Author Comment

    by:omom
    >>What tabs do you have
    Project setting tabs are:
    General, Debug, Fortran, C/C++, Resources, Browse Info, Custom Build, Pre-link step, Post-build step

    >>Are you using an external makefile?
    The first line of foo.mak (the project make file) reads:
    # Microsoft Developer Studio Generated NMAKE File, Format Version 40001

    0
     
    LVL 1

    Expert Comment

    by:speedguns
    Hey Omom,  Which setting do you want to change on the link tab,  I will look on my VC to  to see what the command line option is,  and you can enter it elsewhere (other than the link tab)  ?

    By the way,  the real problem here, is that the link tab is missing from your settings dialog,   I wonder how
    one goes about getting that back,  I am sure it's a function of you workspace.  I will check out a working
    workspace on my machine on monday, and get back to you if, you havn't closed this yet.
    0
     
    LVL 11

    Expert Comment

    by:alexo
    Assuming

    Open the makefile with your favorite editor.
    Find the LINK32_FLAGS entries.
    Add /nodefaltlib to each.
    0
     

    Author Comment

    by:omom
    speedguns:
    I would definitely appreciate whatever you can find out about the link tab
    0
     

    Author Comment

    by:omom
    alexo:
    Since thet make file is generated by Dev Studio, if I make the change suggested, will it not the file be written over and the changes lost?
    0
     
    LVL 11

    Expert Comment

    by:alexo
    I don't know, you have a weird setup...

    If you have a .dsp file, add the switch to lines beginning with either:
    # ADD BASE LINK32
    # ADD LINK32
    0
     
    LVL 1

    Expert Comment

    by:speedguns
    You do have a weird setup,  but instead of typing alexo's suggestion (which is probably the correct answer)
    into the makefile,  can you just stuff it into the project options in the C/C++ tab?  Might not work though,  not
    like the simple solution to the Directory thing.  
    0
     
    LVL 11

    Expert Comment

    by:alexo
    >> can you just stuff it into the project options in the C/C++ tab?

    It will not work because it is a linker option, not a compiler one.
    0
     

    Author Comment

    by:omom
    Hold on, please...fighting fires...also, I may try reinstalling VC++ to see if I get a link tab.
    0
     
    LVL 11

    Expert Comment

    by:alexo
    Before you reinstall, try just creating a new C++ project and see if that one has a "link" tab.  If so, it might be better for you to migrate your project to a new one.
    0
     

    Author Comment

    by:omom
    Ok, let?s start once again?the error is:

    Linking...
    nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj)
    nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in LIBCMTD.lib(dbgdel.obj)
    .\Debug\Ecotone.exe : fatal error LNK1169: one or more multiply defined symbols found
    Error executing link.exe.

    Contrary to my original statement AN EXTERNAL LINK FILE  IS BEING USED.

    alexo:
    You suggested to add /nodefaltlib to LINK32_FLAGS
    I have 2 lines in the make file like this:

    LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib LIB00.lib /nologo /subsystem:windows /pdb:none /debug\

    I added /nodefaultlib, to no effect, but that might be jummping the gun.

    There is a problem with the file path.
    When I do a Rebuild All, it can?t find the source code because the path is wrong.  For example, the file is in C:\dir1\dir2\foo.cpp.  The compiler says it can?t c:\dir1\dir2\dir2\foo.cpp. Notice -> ?dir2\dir2?
    0
     

    Author Comment

    by:omom
    It occurs to me that I'm proceeding incorrectly.

    I've inherited this project, with none of previous authors around to give me any direction, so I'm learning as I go.

    I've discerned that the project was built with an external make file.  I've never done this, I've only built C++ projects from within VC++.  So I am probably not taking the proper steps to build correctly.
    0
     
    LVL 11

    Expert Comment

    by:alexo
    Why don't you scrap this project and built a new one from scratch?  You can copy most settings from the existing makefile.

    Then, you can generate a makefile from the project.
    0
     

    Author Comment

    by:omom
    Originally, I did a File -> Open Workspace, then selected the foo.mak file.  VC++ then creates the project from the make file.  So at this point I have a project, but I get the previously mention errors.  Do I need to build from the command prompt?

    I would like to continue using building the project via the make file.  I think this makes it easier to move to another system.

    0
     
    LVL 11

    Expert Comment

    by:alexo
    I meant, create a *new* project from scratch.
    0
     

    Author Comment

    by:omom
    Ok, i have a link tab

    according to instructions at support.microsoft.com:

    * Open the Project Settings dialog box by clicking Settings on the Build menu.
    * In the Settings For view, click to select (highlight) the project configuration that is getting the link errors.
    * Click the Link tab.
    * Click to select INPUT in the Category combo box.
    * In the Libraries to Ignore edit box, insert the library names (for example, Nafxcwd.lib Libcmtd.lib).

    I add these 2 libraries to the "Ignore Libraries" list but i get the same link errors

    I check "Ignore All Default Libraries" and I get hundreds of errors of unresolved external symbols

    What to try next?

    0
     

    Author Comment

    by:omom
    Also, this link error occurs only when building for Debug.  When building for Release, no errors.
    0
     
    LVL 11

    Accepted Solution

    by:
    You need to change the order in which the libraries are linked.  Try this:
    http://support.microsoft.com/default.aspx?scid=kb;EN-US;q148652
    0
     

    Author Comment

    by:omom
    Ok, the answer is to add Nafxcwd.lib Libcmtd.lib to the Ignore Libraries field AND add them to the front of the Object Library Modules
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    Excel VBA code won't run on some computers 4 26
    TFS Branching 4 58
    Slow process to read Excel 15 62
    dialer.exe 4 20
    This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
    zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    678 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    32 Experts available now in Live!

    Get 1:1 Help Now