Zig cc to compile Kitty term targeting glibc version 2.17 -- issue building GLFW dependency

Hi,

I couldn’t really find meaningful answers on how to deal with this so I’ll ask here.

Long story short, I want to compile Kitty term to target glibc version 2.17 to get it to work on a very specific system I use. For that, I am trying to use zig cc -target flag but I’m having issues compiling the glfw dependency.

My issue happens for now in compiling the glfw dependency for Kitty, at first I had some issues with the include files as I couldn’t figure out how to point it to the X11 headers (which in the end I just copied to another folder to isolate it from the rest of the system’s headers).

Now, I have another issue that glfw tries to use the glibc’s reallocarray function which is available for glibc 2.17 using the _GNU_SOURCE flag (which glfw already uses, therefore that should require no change afaik). In the end, I still get the issue that the function declaration cannot be found:

glfw/x11_window.c:2927:21: error: call to undeclared function 'reallocarray'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
 2927 |         aa->array = reallocarray(aa->array, aa->capacity, sizeof(aa->array[0]));
      |                     ^
glfw/x11_window.c:2927:19: error: incompatible integer to pointer conversion assigning to 'MimeAtom *' (aka 'struct MimeAtom *') from 'int' [-Wint-conversion]
 2927 |         aa->array = reallocarray(aa->array, aa->capacity, sizeof(aa->array[0]));

Given that I saw many people that have already compiled this library using zig cc, this problem should be solvable, but I do require some help here.

Thanks!

It looks like the reallocarray function wasn’t introduced until glibc 2.26.

1 Like

Oh, so it can’t be helped. I guess I would have to use an older version of glfw or backport it.

Thanks for helping out, I will mark the question as solved.

I believe that reallocarray(ptr, num, size) is equivalent to realloc(ptr, num * size), the former just does a check for unsigned overflow. So if that is the only problem it should be easy to patch.

Also I note that the Kitty GLFW is different than the current upstream GLFW. I just tried compiling a little GLFW vulkan app with zig cc targeting x86_64-linux-gnu.2.17 and it built fine.