Link to home
Start Free TrialLog in
Avatar of omom
omom

asked on

LNK2005 error

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

Avatar of alexo
alexo
Flag of Antarctica image

What tabs do you have?  Are you using an external makefile?
Avatar of omom
omom

ASKER

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

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.
Assuming

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

ASKER

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

ASKER

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?
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
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.  
>> 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.
Avatar of omom

ASKER

Hold on, please...fighting fires...also, I may try reinstalling VC++ to see if I get a link tab.
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.
Avatar of omom

ASKER

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?
Avatar of omom

ASKER

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.
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.
Avatar of omom

ASKER

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.

I meant, create a *new* project from scratch.
Avatar of omom

ASKER

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?

Avatar of omom

ASKER

Also, this link error occurs only when building for Debug.  When building for Release, no errors.
ASKER CERTIFIED SOLUTION
Avatar of alexo
alexo
Flag of Antarctica image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of omom

ASKER

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