奇怪的错误C2146和C4430在d3d11shader.h在VS2012
Weird Error C2146 and C4430 in d3d11shader.h in VS2012
所以我是按照书上的说明来创建一个d3d对象。然而,当我试图编译代码时,它在d3d11shader.h中给了我一些奇怪的错误。
在d3dshader.h内,
#include "d3dcommon.h"
//other stuff
typedef struct _D3D11_SIGNATURE_PARAMETER_DESC
{
LPCSTR SemanticName;
UINT SemanticIndex;
UINT Register;
D3D_NAME SystemValueType;
D3D_REGISTER_COMPONENT_TYPE ComponentType;
BYTE Mask;
BYTE ReadWriteMask;
UINT Stream;
D3D_MIN_PRECISION MinPrecision; //Errors here
} D3D11_SIGNATURE_PARAMETER_DESC;
对细节:(1) Error 29 error C2146: syntax error : missing ';' before identifier 'MinPrecision' c:program files (x86)windows kits8.0includeumd3d11shader.h 54
(2) Error 30 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:program files (x86)windows kits8.0includeumd3d11shader.h 54
这很奇怪,因为d3dcommon.h和d3d11shader.h文件都是在Windows SDK和DirectX SDK中定义的,所以我不能改变它们中的任何东西。谁能告诉我怎么修理它?
以下是我的Source.cpp中的代码,这些代码直接从Frank Luna的《3D Game Programming with DirectX11》一书中复制。
#include "d3dApp.h"//This header file is provided by the book
class InitDirect3DApp : public D3DApp
{
public:
InitDirect3DApp(HINSTANCE hInstance);
~InitDirect3DApp();
bool Init();
void OnResize();
void UpdateScene(float dt);
void DrawScene();
};
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance,
PSTR cmdLine, int showCmd)
{
// Enable run-time memory check for debug builds.
#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
InitDirect3DApp theApp(hInstance);
if( !theApp.Init() )
return 0;
return theApp.Run();
}
Init Direct3DApp::InitDirect3DApp(HINSTANCE hInstance)
: D3DApp(hInstance)
{
}
InitDirect3DApp::~InitDirect3DApp()
{
}
bool InitDirect3DApp::Init()
{
if(!D3DApp::Init())
return false;
return true;
}
void InitDirect3DApp::OnResize()
{
D3DApp::OnResize();
}
void InitDirect3DApp::UpdateScene(float dt)
{
}
void InitDirect3DApp::DrawScene()
{
assert(md3dImmediateContext);
assert(mSwapChain);
md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::Blue));
md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);
HR(mSwapChain->Present(0, 0));
}
我注意到的另一件奇怪的事情是,有时当我去D3D_MIN_PRECISION的定义,它引导我到d3dcommon.h, d3dcommon.h中的代码根本没有突出显示。Visual Studio会自动为所有其他文件高亮显示,但这个文件除外。所以我只是假设它不识别代码在这个特定的头文件的一些时间。
而且,当我刚才试图编译代码时,除了前面两个错误之外,还会弹出另一个错误:
31 IntelliSense: identifier "D3D_MIN_PRECISION" is undefined c:Program Files (x86)Windows Kits8.0Includeumd3d11shader.h 54
只是为了你的信息,我在windows 8.1机器上使用vs2012。非常感谢!
你的问题很可能是你混合了Windows 8。x SDK和旧的DirectX SDK标头不正确。
历史上,你会设置INCLUDE和LIB路径,使DXSDK_DIR是第一个,但这只在DirectX SDK头是当前的情况下才有效。现在它们已经过时了,你需要在DXSDK_DIR之前使用WindowsSdkDir(假设你需要使用D3DX这样的东西,这是过时的,只在传统的DirectX SDK中可用;否则你根本不需要它)。
使用VS 2012的"v110"或VS 2013的"v120"平台工具集,如果你还需要使用DirectX SDK,你可以使用vc++的目录设置为Include和Lib:
$(IncludePath);$(DXSDK_DIR)Include
$(LibraryPath);$(DXSDK_DIR)Lib<x86 or x64>
请参阅MSDN, Living Without D3DX, XInput, and XAudio
顺便说一句,如果你试图使用VS 2012的"v110_xp"或VS 2013的"v120_xp"平台工具集,它的工作方式更像以前,会使用传统的顺序。请看这篇博文。
$(DXSDK_DIR)Include;$(IncludePath);
$(DXSDK_DIR)Lib<x86 or x64>;$(LibraryPath)
- 在 vs2012 中,lambda 中的 noexcept 如何工作?
- VS2012 不编译此代码,但 G++、clang 和 ICC 都接受它而无需诊断
- VS2012:“找不到资源编译器DLL.请确保路径正确.”
- 从VS2008升级后,VS2012中的构建项目显示错误
- OpenCV with VS2012 (Qt Support)
- VS2012 中的 is_directory () 对于偶数目录返回 false
- VS2010 和 VS2012 以及 C++11 错误 C2059:语法错误:"..."怎么走?
- 在VS2012中使用C++11条件变量
- std::remove_pointer 无法删除 VS2012 上的常量易失性函数指针
- 标准::variate_generator 在 VS2012 中
- 从命令行运行本机 VS2012/C++ 64 位单元测试
- 仅运行自定义生成规则 - VS2012
- VS2012 bind2nd 不是 std 的成员
- VS2012 C++ DLL compatability
- Delaunay Trangulation for VS2012 C++?
- 获取线路错误 MFC vs2012 (msvcp110.dll)
- Boost 1_52内部版本VS2012失败
- <filesystem> VS2013 与 VS2012 中的不同行为
- libtiff with VS2012
- 奇怪的错误C2146和C4430在d3d11shader.h在VS2012