Maybe update libheif to a newer version.(I am using homebrew to do so on MacOS).
I am having this issue while installing another python library with pi-heif as its dependency on MacOS. Same error about error: call to undeclared function 'heif_image_handle_get_preferred_decoding_colorspace'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration].
There was a 1.16.2version of libheif installed on my computer but the latest version available on homebrew as for now(2025-08-05) is 1.20.1.
I just reinstall the latest version of libheif and it's all right now.