?
Solved

Redefinition of new and delete

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

Technology Partners: 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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

801 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