DirectX C++ 的链接器错误
Linker error with DirectX C++
我正在做一个 Direct X11 项目,我试图在我生成的 window 中绘制一个矩形(整个 window directX 初始化工作正常,因为它编译正确前)。
为此,我包括以下内容 headers :
#include "CommonStates.h"
#include "SpriteBatch.h"
我将这些 headers 中的 link 添加到 C/C++>General>Additional Include Directories,我认为它确实找到了,因为我没有关于包含的错误它。
之后,我尝试编译我的项目。以下几行导致了一些 linker 错误:
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)
我认为这些是一些 linker 错误,所以我将 DirectXTK.lib 文件的路径添加到 Linker>General>Additional Dependencies。我没有找到 CommonStates.lib 和 SpriteBatch.lib 文件,即使我编译了 DirectXTK-master 项目,生成的唯一库是 DirectXTK.lib.
因此,我将 DirectXTK.lib 添加到“链接器”>“输入”>“附加依赖项”。
但是,我仍然出现以下错误:
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'
这意味着您要链接到的库是在与用于构建当前程序的配置不同的配置(调试或发布)中构建的。
修复步骤:
- 在调试和发布中构建库。您将为每个文件(在不同的目录中)获得一个
DirectXTK.lib
文件。
- 在您的主程序中,选择 Debug 作为构建配置,转到 Linker>Input>Additional Dependencies 并添加您刚刚构建的 Debug
DirectXTK.lib
文件。确保将 DirectXTK.lib
文件所在的目录添加到 VC++ Directories>Library Directories。
- 对释放模式重复步骤 2。确保您一次只为一种配置更改这些配置属性。
现在,无论何时在 Debug 模式下构建程序,它都会链接到 Debug 库,对于 Release 也是如此。
我正在做一个 Direct X11 项目,我试图在我生成的 window 中绘制一个矩形(整个 window directX 初始化工作正常,因为它编译正确前)。 为此,我包括以下内容 headers :
#include "CommonStates.h"
#include "SpriteBatch.h"
我将这些 headers 中的 link 添加到 C/C++>General>Additional Include Directories,我认为它确实找到了,因为我没有关于包含的错误它。
之后,我尝试编译我的项目。以下几行导致了一些 linker 错误:
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)
我认为这些是一些 linker 错误,所以我将 DirectXTK.lib 文件的路径添加到 Linker>General>Additional Dependencies。我没有找到 CommonStates.lib 和 SpriteBatch.lib 文件,即使我编译了 DirectXTK-master 项目,生成的唯一库是 DirectXTK.lib.
因此,我将 DirectXTK.lib 添加到“链接器”>“输入”>“附加依赖项”。 但是,我仍然出现以下错误:
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'
这意味着您要链接到的库是在与用于构建当前程序的配置不同的配置(调试或发布)中构建的。
修复步骤:
- 在调试和发布中构建库。您将为每个文件(在不同的目录中)获得一个
DirectXTK.lib
文件。 - 在您的主程序中,选择 Debug 作为构建配置,转到 Linker>Input>Additional Dependencies 并添加您刚刚构建的 Debug
DirectXTK.lib
文件。确保将DirectXTK.lib
文件所在的目录添加到 VC++ Directories>Library Directories。 - 对释放模式重复步骤 2。确保您一次只为一种配置更改这些配置属性。
现在,无论何时在 Debug 模式下构建程序,它都会链接到 Debug 库,对于 Release 也是如此。