Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting LNK2005 errors, trying to create project.

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
I may be overlooking something pretty simple, but, when I link my project, I get a LNK2005 error for every function/method I define, and the compiler claims that they're already defined in main.obj (the file I build), followed by a "fatal error LNK1169: one or more multiply defined symbols found". I started as a Console Application... any help offered to a n00b is appreciated. =)
 
From the date of your posting, I assume you've given up or found the answer yourself (I JUST joined). Anyway, here is the answer to the LNK2005 problem:

MFC, by design, links Libcmtd.lib before Nafxcwd.lib (debug mode). Thus, you can get the LNK2005. Other libraries can cause this, especially when you go to build the release version.

OK... How do you find out which libraries are causing the problem?

In the Project Options: edit box, ensure that the option
/verbose:lib
is present. Run a build and note the diagnostics; you'll pretty easily see the libraries causing the problem. For example:
Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\LIBCMTD.lib:
Searching C:\Program Files\Microsoft Visual Studio\VC98\LIB\OLDNAMES.lib:
Searching C:\Program Files\Microsoft Visual Studio\VC98\MFC\LIB\nafxcwd.lib:
nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in LIBCMTD.lib(dbgdel.obj)

See? NAFXCWD suffered the error but it was conflicting with LIBCMTD.

You can override link order as follows:
1- Project menu Settings item
Opens Project Settings dialog box
2- Select build goal in the Settings For: drop down list
3- Click the Link tab
4- Select Input in the Category: drop down
5- Apply names (any order) of the offending libraries in the Ignore libraries: edit box
LIBCMTD.LIB NAFXCWD.LIB
6- Do the same thing in the Object/library modules: edit box BUT ENSURE THAT THE ORDER IS PROPER
NAFXCWD.LIB LIBCMTD.LIB
7- Click OK and rebuild

Are you using Visual .NET? There is a slightly different method of setting properties, but the concepts are the same.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top