D3D编程的常见报错及解决

d3dapp.cpp(136): error C2664: 'wcscpy' : cannot convert parameter 1 from 'CHAR [32]' to 'wchar_t *'
1> Types pointed to are unrelated;

这是用龙书会出现的常见错误,把Character set改成Unicode或者多字节字符集试试

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~·

error LNK2019: unresolved external symbol "public: int __thiscall D3DApp::run(void)" (?run@D3DApp@@QAEHXZ) referenced in function _WinMain@16
1>Init Direct3D.obj : error LNK2019: unresolved external symbol "public: __thiscall D3DApp::D3DApp(struct HINSTANCE__ *)" (??0D3DApp@@QAE@PAUHINSTANCE__@@@Z) referenced in function "public: __thiscall InitDirect3DApp::InitDirect3DApp(struct HINSTANCE__ *)" (??0InitDirect3DApp@@QAE@PAUHINSTANCE__@@@Z)
1>Init Direct3D.obj : error LNK2001: unresolved external symbol "public: virtual long __thiscall D3DApp::msgProc(unsigned int,unsigned int,long)" (?msgProc@D3DApp@@UAEJIIJ@Z)

这类错误,通常是你声明了函数却没有给出实现。解决方法是,写出实现或者增加相应的DLL。增加DLL的方法可以在代码中使用 #pragma comment (lib,"XX.lib"),也可以在项目属性input 中添加

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~·

d3dApp.obj : error LNK2019: 无法解析的外部符号 _D3DX10CreateFontIndirectW@12,该符号在函数 "public: virtual void __thiscall D3DApp::initApp(void)" (?initApp@D3DApp@@UAEXXZ) 中被引用
1>d3dApp.obj : error LNK2019: 无法解析的外部符号 _DXTraceW@20,该符号在函数 "public: virtual void __thiscall D3DApp::onResize(void)" (?onResize@D3DApp@@UAEXXZ) 中被引用
1>d3dApp.obj : error LNK2019: 无法解析的外部符号 _D3D10CreateDeviceAndSwapChain@32,该符号在函数 "protected: void __thiscall D3DApp::initDirect3D(void)" (?initDirect3D@D3DApp@@IAEXXZ) 中被引用
1>d3dUtil.obj : error LNK2019: 无法解析的外部符号 _D3DXVec3Normalize@8,该符号在函数 "void __cdecl BuildGeoSphere(unsigned int,float,class std::vector<struct D3DXVECTOR3,class std::allocator<struct D3DXVECTOR3> > &,class std::vector<unsigned long,class std::allocator<unsigned long> > &)" (?BuildGeoSphere@@YAXIMAAV?$vector@UD3DXVECTOR3@@V?$allocator@UD3DXVECTOR3@@@std@@@std@@AAV?$vector@KV?$allocator@K@std@@@2@@Z) 中被引用

其实这个报错跟上面那种是属于同一种错误,之所以拿出来另作为一种错误,是因为一下几个LIB在DX10编程中尤其需要记住。

d3d10.lib
d3dx10d.lib
dxerr.lib
dxguid.lib

每新建工程的时候,在“项目”-“属性”-“链接器”-“附加依赖项”中增加上面的lib。(之前我一直以为是MFC与dx的问题,晕)

原文地址:https://www.cnblogs.com/CAION/p/2798785.html