I am on day 12 of handmade hero and the most annoying problem rn is that I get errors from LSP for ex. Assert-> is undeclared indentifier as it was defined in win32_handmade.h but i am using it in handmade.cpp/handmade.h which do not include win32_handmade.h directly
The compiler is doing its job and there are no build errors but in nvim/helix editor i am facing these issues... is there a fix?(I am currently redefining them) Redefining works but in win32_handmade.h i also use BITMAPINFO which is from windows'h included in win32_handmade.cpp so for this one for removing the errors from editor all i can do is use #ifndef and include windows.h again for errors to go away and its really very problematic... what should i do?
I can place them at different locations than what casey does but i am only a begginer so i would not do it if there is another way out.
It's weird that the LSP doesn't work, if the code compiles, but I don't use LSPs so I don't know.
I don't remember exactly what the code looks like, but what you could do is to add include guards (or #pragma once
) into every header and include the headers when necessary, just like if you were using multiple translation units.
/* shared.h */ #if !defined( SHARED_H ) #define Assert... #define SHARED_H #endif /* In every file that needs to use Assert */ #include "shared.h"
Handmade Hero's code is structured using a unity build (everything compiled as a single translation unit), but clangd is defective for code organized that way:
https://github.com/clangd/clangd/issues/45
There are some workarounds discussed in the comments on that github issue.