Solved

Redefinition of new and delete

Posted on 2000-03-22
4
511 Views
Last Modified: 2012-06-21
I am trying to build a program that uses DAO, and for some reason it will work on my machine, but not on the machine that I am developing for. I am grasping at straws at the moment, and so I am trying to build it linking with MFC in a static library, but I can get rid of the linker errors:

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)

nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int,int,char const *,int)" (??2@YAPAXIHPBDH@Z) already defined in LIBCMTD.lib(dbgnew.obj)

Can anyone tell me what might be causing these?
    Regards,
        Bob
0
Comment
Question by:tgemini
[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
  • 2
4 Comments
 
LVL 5

Expert Comment

by:Wyn
ID: 2647955
Qd:In "C++" tab of "Settings" dialog in category "Code Generatoin" check that you have "Multithreaded" in "use runtime library" combobox.

Regards
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2647966
Btw ,All above in the Project Menu in VC IDE...

Hope helpful

Regards
W.Yinan
0
 

Author Comment

by:tgemini
ID: 2651107
It was already on Debug Multithreaded, and when I changed that to anything else it spat the dummy even worse.
0
 
LVL 3

Accepted Solution

by:
Try earned 100 total points
ID: 2656224
When the C Run-Time (CRT) library and MFC libraries are linked in the wrong order, LNK2005 errors occur like what you have experienced.

CAUSE:

The CRT libraries use weak external linkage for the new, delete, and DllMain functions.  The MFC libraries also contain new, delete, and DllMain functions, requiring MFC to be linked before the CRT libraries.

There are two ways to resolve this problem.  The first solution involves forcing the linker to link the libraries in the correct order.  The second solution allows you to find the module that's causing the problem and correct it.

----------------------------

Solution One:

Force Linker to Link Libraries in Correct Order.

1)  Open the Project Settings dialog box by clicking Settings on the Build menu.

2)  In the Settings For view, select (i.e. highlight) the project configuration that's getting the link errors.

3)  Click the Link tab.

4)  Select INPUT in the Category combo box.

5)  In the 'Libraries to Ignore' edit box, insert the library names (for example, Nafxcwd.lib, Libcmtd.lib, etc.)

NOTE: The linker command line equivalent in /NOD:<library name>

6)  In the Object/library Modules edit box, insert the library names.  You must ensure that these are listed in order and as the first two libraries in the line (for example, Nafxcwd.lib Libcmtd.lib, etc.).

-------------------------------

Solution Two:

Find the Problem Module and Correct It
(Perform the following steps to see the current library link order.)

1)  Open the Project Settings dialog box by clicking 'Settings' on the Build menu.

2)  In the 'Settings For' view, Select (highlight) the project configuration that's getting the link errors.

3)  Click the 'Link' tab then type the following in the 'Project Options' dialog box:

/verbose:lib


Rebuild your project.  The libraries will now be listed in the output window during the linking process.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

705 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