繁体   English   中英

DirectX C ++的链接器错误

[英]Linker error with DirectX C++

我正在研究Direct X11项目,并且试图在生成的窗口中绘制一个矩形(整个窗口的DirectX初始化工作得很好,因为它之前已经正确编译了)。 为此,我包括以下标题:

#include "CommonStates.h"
#include "SpriteBatch.h"

我将这些标头的链接添加到C / C ++> General> Additional Include Directories,我认为它确实找到了它,因为我对包含它没有错误。

之后,我尝试编译我的项目。 以下几行导致了一些链接器错误:

RECT *try1 = new RECT();
try1->bottom = 0; try1->left = 0; try1->right = 50; try1->bottom = 50;

CommonStates states(d3dDevice);
sprites->Begin(SpriteSortMode_Deferred, states.NonPremultiplied());
sprites->Draw(textureRV, XMFLOAT2(50, 50), try1, Colors::Black);
sprites->End();

错误:

1>Framework.obj : error LNK2019: unresolved external symbol "public: __thiscall DirectX::CommonStates::CommonStates(struct ID3D11Device *)" (??0CommonStates@DirectX@@QAE@PAUID3D11Device@@@Z) referenced in function "public: void __thiscall Framework::Draw2(unsigned long *)" (?Draw2@Framework@@QAEXPAK@Z)
1>Framework.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall DirectX::CommonStates::~CommonStates(void)" (??1CommonStates@DirectX@@UAE@XZ) referenced in function "public: void __thiscall Framework::Draw2(unsigned long *)" (?Draw2@Framework@@QAEXPAK@Z)
1>Framework.obj : error LNK2019: unresolved external symbol "public: struct ID3D11BlendState * __cdecl DirectX::CommonStates::NonPremultiplied(void)const " (?NonPremultiplied@CommonStates@DirectX@@QBAPAUID3D11BlendState@@XZ) referenced in function "public: void __thiscall Framework::Draw2(unsigned long *)" (?Draw2@Framework@@QAEXPAK@Z)
1>Framework.obj : error LNK2019: unresolved external symbol "public: void __vectorcall DirectX::SpriteBatch::Begin(enum DirectX::SpriteSortMode,struct ID3D11BlendState *,struct ID3D11SamplerState *,struct ID3D11DepthStencilState *,struct ID3D11RasterizerState *,class std::function<void __cdecl(void)>,struct DirectX::XMMATRIX)" (?Begin@SpriteBatch@DirectX@@QAQXW4SpriteSortMode@2@PAUID3D11BlendState@@PAUID3D11SamplerState@@PAUID3D11DepthStencilState@@PAUID3D11RasterizerState@@V?$function@$$A6AXXZ@std@@UXMMATRIX@2@@Z) referenced in function "public: void __thiscall Framework::Draw2(unsigned long *)" (?Draw2@Framework@@QAEXPAK@Z)
1>Framework.obj : error LNK2019: unresolved external symbol "public: void __cdecl DirectX::SpriteBatch::End(void)" (?End@SpriteBatch@DirectX@@QAAXXZ) referenced in function "public: void __thiscall Framework::Draw2(unsigned long *)" (?Draw2@Framework@@QAEXPAK@Z)
1>Framework.obj : error LNK2019: unresolved external symbol "public: void __vectorcall DirectX::SpriteBatch::Draw(struct ID3D11ShaderResourceView *,struct DirectX::XMFLOAT2 const &,union __m128)" (?Draw@SpriteBatch@DirectX@@QAQXPAUID3D11ShaderResourceView@@ABUXMFLOAT2@2@T__m128@@@Z) referenced in function "public: void __thiscall Framework::Draw2(unsigned long *)" (?Draw2@Framework@@QAEXPAK@Z)
1>Framework.obj : error LNK2001: unresolved external symbol "private: static struct DirectX::XMMATRIX const DirectX::SpriteBatch::MatrixIdentity" (?MatrixIdentity@SpriteBatch@DirectX@@0UXMMATRIX@2@B)

我发现这些是一些链接器错误,因此我将DirectXTK.lib文件的路径添加到了Linker> General> Additional Dependencies。 尽管我编译了DirectXTK-master项目,但我找不到CommonStates.lib或SpriteBatch.lib文件,生成的唯一库是DirectXTK.lib。

因此,我将DirectXTK.lib添加到了Linker> Input> Additional Dependencies。 但是然后,我仍然出现以下错误:

1>DirectXTK.lib(CommonStates.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in AddForceMessage.obj
1>DirectXTK.lib(CommonStates.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in AddForceMessage.obj
1>DirectXTK.lib(SpriteBatch.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in AddForceMessage.obj
1>DirectXTK.lib(SpriteBatch.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in AddForceMessage.obj
1>DirectXTK.lib(pch.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in AddForceMessage.obj
1>DirectXTK.lib(pch.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in AddForceMessage.obj
1>DirectXTK.lib(VertexTypes.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in AddForceMessage.obj
1>DirectXTK.lib(VertexTypes.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in AddForceMessage.obj
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library

所以我真的不明白这是什么意思,请您告诉我我做错了什么,应该怎么做才能使它起作用? 非常感谢你。

 mismatch detected for '_ITERATOR_DEBUG_LEVEL' 

这意味着您要链接的库是用与用于构建当前程序的库不同的配置(调试或发行版)构建的。

解决步骤:

  1. 在Debug和Release中构建库。 您将为每个文件(在不同目录中)获得一个DirectXTK.lib文件。
  2. 在主程序中,选择“调试”作为构建配置,转到“链接器”>“输入”>“其他依赖项”,然后添加刚刚构建的Debug DirectXTK.lib文件。 确保将DirectXTK.lib文件所在的目录添加到VC ++目录>库目录。
  3. 对释放模式重复步骤2。 确保您一次仅更改一种配置的这些配置属性。

现在,每当您在Debug模式下构建程序时,该程序都将链接到Debug库,对于Release库也是如此。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM