c++ - Visual Studio 链接错误 LNK2005 和 LNK2020

标签 c++ visual-studio linker

我正在使用 visual studio 2003,但在我的项目中出现以下链接错误:

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

然后我将 libcmtd.lib 包含到“忽略特定库”行中并得到另一个错误:

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

这是我的主课的开始:

#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;
...
}

我将我正在使用的所有库都包含在链接器属性中。这是它的命令行输出:

/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"

我是 C++ 的新手,我不太了解链接的工作原理 :) 所以非常感谢您的帮助。

最佳答案

您正在链接一个 .lib,其代码是使用不兼容的编译器设置编译的。第一个问题是项目 + 属性、C/C++、代码生成、运行时库。/MD 与/MT 不兼容。您要么必须重建 .libs 以匹配您的 .exe 项目设置,要么反之亦然。

关于c++ - Visual Studio 链接错误 LNK2005 和 LNK2020,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2117452/

相关文章:

c++ - 有没有什么办法可以告诉 clang 在没有其他优化的情况下生成 TBAA 元数据?

c++ - "error MSB8020: The build tools for v141 (Platform Toolset = ' v141 ') cannot be found"尝试安装 npm 模块 scrypt

c++ - 元组在 VS2012 中如何工作?

Xcode 不断在错误的路径上搜索 dylib

c++ - 将 glbinding 与 cmake 链接起来

c++ - "Function"不是 C++ 类型

c++ - SDL2.DLL 丢失

c++ - GCC:错误:表达式后出现垃圾 `:0x+57f120'

git - MSBuild 和 Jenkins : where to put credentials?

c++ - 每次在 Visual Studio 2015 中编译项目时是否都必须链接 .lib 文件?