Solved

LNK2005 error

Posted on 2001-11-02
20
922 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
Comment
Question by:omom
  • 10
  • 8
  • 2
20 Comments
 
LVL 11

Expert Comment

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

Author Comment

by:omom
ID: 6614471
>>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
ID: 6614768
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 11

Expert Comment

by:alexo
ID: 6614790
Assuming

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

Author Comment

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

Author Comment

by:omom
ID: 6614828
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
ID: 6614846
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
ID: 6614907
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
ID: 6615306
>> 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
ID: 6624812
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
ID: 6625020
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
ID: 6660522
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
ID: 6662022
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
ID: 6662142
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
ID: 6662212
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
ID: 6662420
I meant, create a *new* project from scratch.
0
 

Author Comment

by:omom
ID: 6693095
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
ID: 6693106
Also, this link error occurs only when building for Debug.  When building for Release, no errors.
0
 
LVL 11

Accepted Solution

by:
alexo earned 200 total points
ID: 6693108
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
ID: 6693165
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

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Clean Uninstall of VS Professional 2015 5 52
GUI: DIalog Stacking and Popping in MS C++ 4 76
Trouble with References... 5 55
What .NET URL re-routing tool did I use? 2 56
This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

821 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