Nuklear icon indicating copy to clipboard operation
Nuklear copied to clipboard

Some examples can break due to dependency on headers coming from different files

Open sleeptightAnsiC opened this issue 2 months ago • 2 comments

Many demo examples make an assumption that they can use symbols coming from a different file, due to indirect header inclusion.

For example, Nuklear/demo/common/overview.c uses libm math symbols, but never includes <math.h> or any similar header:

https://github.com/Immediate-Mode-UI/Nuklear/blob/fcd64f85e54b9d35eee13347748d70fa4d2e134e/demo/common/overview.c#L1-L3

https://github.com/Immediate-Mode-UI/Nuklear/blob/fcd64f85e54b9d35eee13347748d70fa4d2e134e/demo/common/overview.c#L754-L759

This breaks, if I try to provide my own NK_SIN/NK_COS/STBTT_sqrt/etc in one of the demo files, and then remove the math header there.

This has happened to me when working on updated sdl3_renderer. In newer version of SDL3, <SDL3/SDL.h> does not pull <math.h> any more, and provides its own version of math symbols.

Note that Nuklear/demo/common/overview.c and <math.h> is just an example here. More demos are affected by this issue due to all kinds of headers.

sleeptightAnsiC avatar Nov 04 '25 18:11 sleeptightAnsiC

Note: header inclusion can be traced by compiler: GCC and Clang can do this with -H flag

Another note: https://include-what-you-use.org/ can help with issues like this one, but I don't believe it works when including source files.

sleeptightAnsiC avatar Nov 04 '25 18:11 sleeptightAnsiC

Definitely something we should fix up. I think optimally we'd be defining our own NK_INT_MAX, and maybe even move away from time.h entirely.

RobLoach avatar Nov 06 '25 17:11 RobLoach