Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

LNK2005 error

Posted on 2001-11-02
20
Medium Priority
?
937 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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 800 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

618 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