0

I'm using clang++ that links to MSVC.

I compiled shaders (DirectXTK\Shaders) and included SpriteBatch and SpriteFont in my source code.

If I include just the header files (.h), I get linking errors; if I include source files (.cpp; with or without .h), I get this:

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))

I tried to find the solution on the GitHub issues page of DirectXTK, on this website and on the web, but didn't find anything helpful.

1 Answers1

2

The Windows headers define a 'min' and 'max' macro that interacts poorly with std::min/std::max from <algorithm>.

In all my templates and tests, I define NOMINMAX before using Windows.h to avoid this problem. It's generally a better practice. If you still need to use a macro form while doing this, you can use __min/_max.

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

#include <Windows.h>

See this other thread and this blog post

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
  • Thank you, this resolved the issue with min/max, but now I get linker errors that are coming from `SpriteBatch` and `SpriteFont` source files. The errors are about external symbols, such as `DirectX::BinaryReader`, `struct ID3D11RasterizerState`, etc. being referenced in functions, such as `DirectX::SpriteBatch::Impl::PrepareForRendering(void)` and `DirectX::SpriteFont::SpriteFont`. Those are unrelated to my code, since I commented out parts that are referring to my font implementation. Did I miss linking a specific static library? – Heap Overflew Aug 13 '20 at 06:50
  • Answering my question - yes, it seems like I also had to include `BufferHelpers`, `CommonStates`, `VertexTypes`, and `BinaryReader`. Maybe I miss something, but I don't understand why do I need to include those, since I already gave my compiler the include paths to these files. – Heap Overflew Aug 13 '20 at 08:56
  • Your program needs to link with the static library ``DirectXTK.lib`` to work. Take a look at ``CMakeLists.txt`` for build details if you are not using Visual Studio. – Chuck Walbourn Aug 13 '20 at 17:16
  • I was linking to `DirectXTK.lib` (since I was using texture functions), but it seems like that wasn't enough, and I grep'ed functions in the error list and included corresponding source files. – Heap Overflew Aug 13 '20 at 17:51