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

x
?
Solved

Redefinition of new and delete

Posted on 2000-03-22
4
Medium Priority
?
513 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 400 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

609 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