【问题标题】:SpriteBatch and SpriteFont (DirectXTK) throw an error (expected unqualified-id)SpriteBatch 和 SpriteFont (DirectXTK) 抛出错误(预期的 unqualified-id)
【发布时间】:2020-08-12 18:21:28
【问题描述】:

我正在使用链接到MSVCclang++

我编译了着色器 (DirectXTK\Shaders) 并在我的源代码中包含了 SpriteBatchSpriteFont

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

SpriteBatch.cpp:532:27: error: expected unqualified-id
    size_t newSize = std::max(InitialQueueSize, mSpriteQueueArraySize * 2);
                          ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\minwindef.h:193:29: note: expanded from macro 'max'
#define max(a,b)            (((a) > (b)) ? (a) : (b))

我试图在 DirectXTK 的 GitHub 问题页面、本网站和网络上找到解决方案,但没有发现任何帮助。

【问题讨论】:

    标签: c++ directx directx-11


    【解决方案1】:

    Windows 标头定义了一个“最小”和“最大”宏,与来自<algorithm>std::min/std::max 交互不佳。

    在我所有的模板和测试中,我在使用Windows.h 之前定义了NOMINMAX 以避免这个问题。这通常是一种更好的做法。如果在执行此操作时仍需要使用宏形式,可以使用__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

    【讨论】:

    • 谢谢,这解决了 min/max 的问题,但现在我收到来自 SpriteBatchSpriteFont 源文件的链接器错误。错误与外部符号有关,例如DirectX::BinaryReaderstruct ID3D11RasterizerState 等在函数中被引用,例如DirectX::SpriteBatch::Impl::PrepareForRendering(void)DirectX::SpriteFont::SpriteFont。这些与我的代码无关,因为我注释掉了引用我的字体实现的部分。我错过了链接特定的静态库吗?
    • 回答我的问题 - 是的,看来我还必须包括 BufferHelpersCommonStatesVertexTypesBinaryReader。也许我错过了一些东西,但我不明白为什么我需要包含这些,因为我已经为我的编译器提供了这些文件的包含路径。
    • 您的程序需要与静态库DirectXTK.lib 链接才能工作。如果您不使用 Visual Studio,请查看 CMakeLists.txt 了解构建详细信息。
    • 我链接到DirectXTK.lib(因为我使用的是纹理函数),但这似乎还不够,我在错误列表中添加了函数并包含了相应的源文件。
    猜你喜欢
    • 1970-01-01
    • 2015-08-07
    • 2011-10-27
    • 1970-01-01
    • 1970-01-01
    • 2014-03-07
    • 2011-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多