0

我正在尝试从 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”,那么就没有歧义的余地,函数已定义并基本上复制+粘贴到生成链接器错误的同一源文件中,但我仍然收到链接器错误。

我忽略了什么吗?

4

3 回答 3

2

您已经在 include/source 文件夹中添加了文件,但是库呢?对我来说,这更像是一个库问题(缺少 .lib)。

也许您还需要在 Linker - Input 中列出您的依赖项。

LNK2005 通常意味着附加库未正确链接。

于 2009-05-24T19:16:40.927 回答
2

您可能忘记链接到 SDK 库文件之一。您可以在 Linker->Input->Additional Dependencies 下的项目属性中进行设置,或使用#pragma 注释

于 2009-05-24T19:16:59.803 回答
2

发生这种情况是因为:

1 .lib 的源代码丢失,如 tomzx 或 Daniel,或 2 它是在另一个版本的 Visual C 中编译的 .lib 尝试在记事本中创建文件,如 .c(不是 .cpp),然后添加到您的项目文件.c(项目...添加到项目...文件)

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

于 2009-10-09T14:16:02.463 回答