Solved

Redefinition of new and delete

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

760 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

21 Experts available now in Live!

Get 1:1 Help Now