Visual Studio linking error LNK2005 and LNK2020

2019-07-29 02:55发布

问题:

I'm using visual studio 2003 and I'm getting the following linking error in my project:

Linking...
LINK : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
msvcrtd.lib(MSVCR71D.dll) : error LNK2005: _fprintf already defined in LIBCMTD.lib(fprintf.obj)
C:\Documents and Settings\mz07\Desktop\project\HLconsoleExample\Debug\HLconsoleExample.exe : fatal error LNK1169: one or more multiply defined symbols found

I then included libcmtd.lib into "ignore specific library" line and got another error:

Linking...
LINK : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
LINK : error LNK2020: unresolved token (0A000037) _CxxThrowException
LINK : error LNK2020: unresolved token (0A000039) delete
LINK : fatal error LNK1120: 2 unresolved externals

This is the beginning of my main class:

#include <cstdio>
#include <iostream>

#if defined(WIN32)
# include <conio.h>
#else
# include "conio.h"
#endif

#include <HL/hl.h>
#include <HD/hd.h>

#include <HDU/hduVector.h>
#include <HDU/hduError.h>
...
int main(int argc, char *argv[])
{
  HHD hHD;
  HHLRC hHLRC;
  HDErrorInfo error;
...
}

I included all the libraries I'm using into the Linker properties. Here is the Command Line output of it:

/OUT:"C:\Documents and Settings\mz07\Desktop\project\HLconsoleExample\Debug\HLconsoleExample.exe" /INCREMENTAL /NOLOGO /NODEFAULTLIB:"libcmtd.lib" /DEBUG /ASSEMBLYDEBUG /PDB:"C:\Documents and Settings\mz07\Desktop\project\HLconsoleExample\Debug/HLconsoleExample.pdb" /FIXED:No hl.lib hd.lib HDUD.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "\Program Files\SensAble\3DTouch\lib\hl.lib" "\Program Files\SensAble\3DTouch\lib\hd.lib" "\Program Files\SensAble\3DTouch\utilities\src\Hdu\Debug\HDUD.lib"

I am new to c++ and I don't really understand how linking works :) so any help is appreciated.

回答1:

You are linking a .lib whose code was compiled with an incompatible compiler setting. The problem one is Project + Properties, C/C++, Code Generation, Runtime library. /MD is not compatible with /MT. You'll either have to rebuild the .libs to match your .exe project setting or the other way around.