FIX for "undefined reference to 'av_mallocz_array"

The place to discuss linux version of MakeMKV
Post Reply
nrk666
Posts: 2
Joined: Mon Feb 27, 2023 1:59 pm

FIX for "undefined reference to 'av_mallocz_array"

Post by nrk666 »

When compiling makemkv-oss against latest ffmpeg with libfdk-aac, "av_mallocz_array" has been deprecated in ffmpeg https://patchwork.ffmpeg.org/project/ff ... tlook.com/ .

The fix for this is to edit makemkv-oss source file libffabi/src/ffabi.c and replace "av_mallocz_array" with "av_calloc" and recompile.
cas206
Posts: 15
Joined: Mon May 17, 2021 7:20 pm

Re: FIX for "undefined reference to 'av_mallocz_array"

Post by cas206 »

Same error on Linux Mint 21.1. This fix worked. Thanks.
fang2811
Posts: 1
Joined: Wed Mar 29, 2023 2:00 am

Re: FIX for "undefined reference to 'av_mallocz_array"

Post by fang2811 »

I encountered the same compile error on archlinux today.

Code: Select all

> pacman -Q ffmpeg openssl expat mesa qt5-base zlib gcc
ffmpeg 2:6.0-4
openssl 3.0.8-1
expat 2.5.0-1
mesa 23.0.1-1
qt5-base 5.15.8+kde+r185-1
zlib 1:1.2.13-2
gcc 12.2.1-2
Here's the specific patch that I applied (based on nrk666's comment)

Code: Select all

diff --git a/libffabi/src/ffabi.c b/libffabi/src/ffabi.c
index 5dda9e1..2b29b87 100644
--- a/libffabi/src/ffabi.c
+++ b/libffabi/src/ffabi.c
@@ -478,7 +478,7 @@ FFM_AudioEncodeContext* __cdecl ffm_audio_encode_init(void* logctx,const char* n
 #else
     ctx->frame = av_frame_alloc();
     if (av_sample_fmt_is_planar(ctx->avctx->sample_fmt)) {
-        ctx->frame_extended_data = av_mallocz_array(ctx->avctx->channels,
+        ctx->frame_extended_data = av_calloc(ctx->avctx->channels,
             sizeof(*ctx->frame_extended_data));
         if (!ctx->frame_extended_data) {
             ffm_audio_encode_close(ctx);
Falco
Posts: 29
Joined: Thu Aug 16, 2018 6:37 pm

Re: FIX for "undefined reference to 'av_mallocz_array"

Post by Falco »

Same on Fedora Linux fresh installation
Thx nrk666 for your trick to solve this issue.
I posted your correction on my post too,
viewtopic.php?f=3&t=30126&p=135117#p135117
STARBASEn
Posts: 1
Joined: Fri Apr 21, 2023 10:13 pm

Re: FIX for "undefined reference to 'av_mallocz_array"

Post by STARBASEn »

I had the same issue today compiling a later download of v1.17.3 for Fedora38 during make, ffabi, undefined variable av_malloc_arrayz, line 481. I just deleted the trailing z and it compiled fine. So it seems both fixes work, at least for now.
Falco
Posts: 29
Joined: Thu Aug 16, 2018 6:37 pm

Re: FIX for "undefined reference to 'av_mallocz_array"

Post by Falco »

Ahah, too cool !
But guys, which is the best value in that case: "av_calloc" or "av_malloc_array" ?
Zirias
Posts: 22
Joined: Mon Apr 22, 2019 3:30 pm

Re: FIX for "undefined reference to 'av_mallocz_array"

Post by Zirias »

Falco wrote:
Sun Apr 23, 2023 11:53 am
But guys, which is the best value in that case: "av_calloc" or "av_malloc_array" ?
The function now removed was named "mallocz", the z means "zero out the memory". If the code relies on the memory being initialized to 0, using "av_malloc_array" instead would most likely lead to crashes.

"av_calloc" OTOH seems to be named after the C standard function "calloc" which DOES zero memory. It's certainly the correct replacement.
Falco
Posts: 29
Joined: Thu Aug 16, 2018 6:37 pm

Re: FIX for "undefined reference to 'av_mallocz_array"

Post by Falco »

Thank you a lot for this really interesting answer. In that case, I will modify my code with it.
mfraz74
Posts: 20
Joined: Wed Feb 07, 2018 11:16 am

Re: FIX for "undefined reference to 'av_mallocz_array"

Post by mfraz74 »

Just tried compiling 1.17.4 and came across this error. Thanks for the fix.

If you want a simple one liner to change this:

Code: Select all

sed -i "s/av_mallocz_array/av_calloc/g" libffabi/src/ffabi.c
nrk666
Posts: 2
Joined: Mon Feb 27, 2023 1:59 pm

Re: FIX for "undefined reference to 'av_mallocz_array"

Post by nrk666 »

I forgot I even submitted this, glad I could help out and return a little love for this app. :D :D :D
Post Reply