SpriteBatch和SpriteFontDirectXTK引发错误预期的非限定ID

问题描述

我正在使用链接clang++的{​​{1}}。

我编译了着色器(MSVC),并在源代码中包含了directxtk\ShadersSpriteBatch

如果仅包含头文件SpriteFont),则会出现链接错误;如果我包含源文件.h;有或没有.cpp),我都会得到:

.h

我试图在directxtk的GitHub问题页面,此网站和Web上找到解决方案,但是没有发现任何帮助。

解决方法

Windows标头定义了一个'min'和'max'宏,这些宏与std::min中的std::max / <algorithm>的交互作用较弱。

在所有模板和测试中,我先定义NOMINMAX,然后再使用Windows.h来避免此问题。通常,这是一种更好的做法。如果在执行此操作时仍需要使用宏格式,则可以使用__min / _max

#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#define NODRAWTEXT
#define NOGDI
#define NOBITMAP
#define NOMCX
#define NOSERVICE
#define NOHELP

#include <Windows.h>

请参见this other threadthis blog post