Solved

Redefinition of new and delete

Posted on 2000-03-22
4
506 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now