c++ - Visual C++ LNK2005、LNK2019 中的链接器错误 - 不确定原因

标签 c++ visual-c++ linker lnk2019 lnk2005

我正在尝试从 nVidia 9.5 SDK 构建代码,但出现以下链接器错误:

>1>NV_D3DCommonDX9U.lib(NV_StringFuncs.obj) : error LNK2005: "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl std::getline<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_istream<char,struct std::char_traits<char> > &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (??$getline@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@YAAAV?$basic_istream@DU?$char_traits@D@std@@@0@AAV10@AAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@@Z) already defined in msvcprtd.lib(MSVCP90D.dll)
1>FogTombScene.obj : error LNK2019: unresolved external symbol "public: struct IDirect3DTexture9 * * __thiscall TextureFactory::CreateTextureFromFile(struct IDirect3DDevice9 *,wchar_t const *,bool)" (?CreateTextureFromFile@TextureFactory@@QAEPAPAUIDirect3DTexture9@@PAUIDirect3DDevice9@@PB_W_N@Z) referenced in function "public: virtual long __thiscall FogTombScene::RestoreDeviceObjects(void)" (?RestoreDeviceObjects@FogTombScene@@UAEJXZ)
1>FogTombScene.obj : error LNK2019: unresolved external symbol "public: long __thiscall LoadXFile::LoadFile(wchar_t const *,bool)" (?LoadFile@LoadXFile@@QAEJPB_W_N@Z) referenced in function "public: virtual long __thiscall FogTombScene::RestoreDeviceObjects(void)" (?RestoreDeviceObjects@FogTombScene@@UAEJXZ)
1>FogTombScene.obj : error LNK2019: unresolved external symbol "public: long __thiscall LoadXFile::Initialize(struct IDirect3DDevice9 *,class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > (__cdecl*)(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &,bool),class TextureFactory * *)" (?Initialize@LoadXFile@@QAEJPAUIDirect3DDevice9@@P6A?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@ABV34@_N@ZPAPAVTextureFactory@@@Z) referenced in function "public: virtual long __thiscall FogTombScene::RestoreDeviceObjects(void)" (?RestoreDeviceObjects@FogTombScene@@UAEJXZ)
1>NV_D3DCommonDX9U.lib(NV_StringFuncs.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::locale::facet::_Register(void)" (__imp_?_Register@facet@locale@std@@QAEXXZ) referenced in function "class std::ctype<char> const & __cdecl std::use_facet<class std::ctype<char> >(class std::locale const &)" (??$use_facet@V?$ctype@D@std@@@std@@YAABV?$ctype@D@0@ABVlocale@0@@Z)
1>NV_D3DCommonDX9U.lib(NV_StringFuncs.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static unsigned int __cdecl std::ctype<char>::_Getcat(class std::locale::facet const * *)" (__imp_?_Getcat@?$ctype@D@std@@SAIPAPBVfacet@locale@2@@Z) referenced in function "class std::ctype<char> const & __cdecl std::use_facet<class std::ctype<char> >(class std::locale const &)" (??$use_facet@V?$ctype@D@std@@@std@@YAABV?$ctype@D@0@ABVlocale@0@@Z)
1>NV_D3DCommonDX9U.lib(NV_StringFuncs.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static unsigned int __cdecl std::ctype<unsigned short>::_Getcat(class std::locale::facet const * *)" (__imp_?_Getcat@?$ctype@G@std@@SAIPAPBVfacet@locale@2@@Z) referenced in function "class std::ctype<unsigned short> const & __cdecl std::use_facet<class std::ctype<unsigned short> >(class std::locale const &)" (??$use_facet@V?$ctype@G@std@@@std@@YAABV?$ctype@G@0@ABVlocale@0@@Z)

我不知道为什么我会遇到这些恐怖的事情,因为我 99% 确定我的目录设置正确。

例如,它找不到的函数之一是 TextureFactory::CreateTextureFromFile,但我已将声明和定义该函数的目录添加到 Visual C++ 设置中的 include/source 目录中。

文件的顶部是这样的:

#include "nvafx.h"
//#include "NV_D3DCommon\NV_D3DCommonDX9.h"  // include library sub-headers
                                             // and add .lib to linker inputs
//#include "NV_D3DMesh\NV_D3DMesh.h"

//#include "shared\NV_Common.h"
//#include "shared\NV_Error.h"

#include "FogTombScene.h"
#include "ThicknessRenderProperties.h"
#include "ThicknessRenderProperties8BPC.h"
#include "../camera.h"


// When the following two lines are added I get more LNK2005 (understandable) 
// but I also still get the same LNK2019 errors as above
#include "texturefactory.h"
#include "texturefactory.cpp"

更重要的是,如果我在出现这些错误的文件顶部说#include“TextureFactory.h”和#include“texturefactory.cpp”,那么就没有歧义的余地,函数已定义并基本上复制并粘贴到生成链接器错误的同一源文件中,但我仍然遇到链接器错误。

我是不是忽略了什么?

最佳答案

那是因为:

1 缺少 .lib 源,如 tomzx 或 Daniel 所说, 或者 2 在另一个版本的 Visual C 中编译的 .lib 尝试在记事本中创建类似 .c(不是 .cpp)的文件,然后将文件 .c 添加到项目中(项目...添加到项目...文件)

对不起,我是墨西哥人,我不会说英语。 萨鲁多斯。

关于c++ - Visual C++ LNK2005、LNK2019 中的链接器错误 - 不确定原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/904416/

相关文章:

python - 逻辑: In a 2D data find and remove duplicates and average the y axis results

c++ - 为什么 VS2017 会警告 "Function definition not found"对于使用输入 typedef 声明但使用原始定义的函数向前?

c++ - 在资源文件 VC++ 中引用 $(SolutionDir)

go - 使用 Gtk+ 的 C 接口(interface)构建 Go

c++ - cpp show result 依赖于之前的结果

c++ - 是否有可能确定/断言,如果一个虚函数被覆盖,另一个虚函数也被覆盖?

c++ - 使用 Visual Studio 2015 时的多个符号定义

makefile - 如何使用 cmake 链接 jemalloc 共享库

c++ - 带括号的 Visual Studio (C++) IntelliSense

visual-c++ - 如果字符串是使用 Visual Studion Windows 窗体从 Visual C++ 中的文本框中获取的,则字符串到整数类型的转换