Android FFmpeg : Undefined references to atof, log2 & log2f
Asked Answered
A

2

6

I am trying to link to FFmpeg built for android using android-ndk-r15c. I built this by downloading FFmpeg source that is latest ffmpeg-3.3.4.

Following are my linker list:

-lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice -lpostproc

I get the following errors complaining

libavformat/hls.c:783: error: undefined reference to 'atof'
libavcodec/ffv1enc.c:146: error: undefined reference to 'log2'
libavcodec/imc.c:428: error: undefined reference to 'log2f'

Following are my FFmpeg related includes:

#include <stdint.h>
#include <cstdlib>

#define __STDC_CONSTANT_MACROS

extern "C" {

#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/mathematics.h"
#include "libavcodec/version.h"
#include "libavutil/rational.h"
#include "libavutil/avstring.h"
#include "libswscale/swscale.h"

}

Following is my buildscript to cross-compile FFmpeg for android:

#!/bin/bash

cd ffmpeg-3.3.4

NDK=/path/to/ndk/android-ndk-r15c
SYSROOT=$NDK/platforms/android-21/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64
AR=$TOOLCHAIN/bin/arm-linux-androideabi-ar
CPREFIX=$TOOLCHAIN/bin/arm-linux-androideabi-ar
CC=$TOOLCHAIN/bin/arm-linux-androideabi-gcc
CXX=$TOOLCHAIN/bin/arm-linux-androideabi-g++
LD=$TOOLCHAIN/bin/arm-linux-androideabi-ld
RANLIB=$TOOLCHAIN/bin/arm-linux-androideabi-ranlib
STRIP=$TOOLCHAIN/bin/arm-linux-androideabi-strip

function build_ffmpeg_android {

./configure \
    --prefix=$PREFIX \
    --disable-stripping \
    --arch=arm \
    --cpu=cortex-a8 \
    --target-os=linux \
    --enable-cross-compile \
    --enable-debug \
    --enable-pic \
    --disable-programs \
    --enable-static \
    --disable-shared \
    --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
    --disable-doc \
    --enable-postproc \
    --enable-swscale \
    --enable-avfilter \
    --enable-avresample \
    --disable-opencl \
    --disable-securetransport \
    --sysroot=$SYSROOT \
    --enable-videotoolbox \
    --enable-avresample \
    --disable-symver \
    #--enable-gpl \
    #--enable-libx264
    $ADDITIONAL_CONFIGURE_FLAG
    make clean
    make -j9
    make install
}

CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"

build_ffmpeg_android

Question:
Which library am I missing to link to ?

Accomplished answered 9/10, 2017 at 14:13 Comment(17)
The standard C++ math functions are in a separate library that needs to be linked, called (plain and simply) m. So add -lm to link with it.Galacto
just add -lm? seems like not enough. any other libraries I need ? I am working with C++14Accomplished
No that's about it. That's the standard C++ (and C for that matter) math library.Galacto
it did not help but thanks anyways. what about the log2 & log2f ?Accomplished
Try maybe adding -lm after your linker list.Allies
adding -lm does not make a difference. I get the same list of errors.Accomplished
Where did you add it? Order may matter. If library A depends on library B, then A must usually come before B on the command line when linking.Galacto
I added it in the end. here is the linker list -lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice -lpostproc -lm. is this correct?Accomplished
Yes it is. That's strange. I think you might have a problem with your glibc libraries. Can you try to compile a little C program that uses atof and log2? BTW, in my system at least, atof is not in libm.a but in libc.a.Allies
By the way, I used the following flags in configure to build FFmpeg. Is this correct ? --extra-cflags="-O3 -Wall -pipe -std=c99 -ffast-math -fstrict-aliasing -Werror=strict-aliasing -Wno-psabi -Wa,--noexecstack -DANDROID -DNDEBUG-march=armv5te -mtune=arm9tdmi -msoft-float"Accomplished
Try to add --extra-ldflags=-L$SYSROOT/usr/lib/. And check what actual link command looks like. It should pick up the system libraries from platforms/android-21/arch-arm/usr/libs.Ruyle
@AlexCohn selecting anything below platforms/android-21 works. You can please post an answer to this topic to close this question properly. thanks for that suggestion. building FFmpeg against latest ndk that is 15c & android-26 was a really bad ideaAccomplished
Wait a sec. The link error about atof(), etc. comes not from your buildscript, but from ndk-build for your app that uses the ffmpeg static libs? And what is your target platform?Ruyle
exact buildscript run below android-21 using ndk r10e works. Yes. no changes to scriptAccomplished
No, I am afraid we didn't understand each other. Let us continue in chatRuyle
See https://mcmap.net/q/610405/-what-is-the-relation-between-app_platform-android-minsdkversion-and-android-targetsdkversionRuyle
For a shorter, less rambling answer: android.googlesource.com/platform/ndk/+/master/docs/user/… (assuming I'm correctly understanding why that answer got linked)Boob
B
1

I ran into this issue building ffmpeg-2.8.15 with x264 using ndk-r10e with platform android-15. I updated the code to use android-21 and it compiled the code without any issues. Our min sdk version is 21.

Bronk answered 30/11, 2018 at 6:41 Comment(0)
M
0

You also have the option to remove those math functions from FFMPEG configure file and rebuild. Your resoling lib-*.so files will no longer call those symbols.

Meilen answered 30/11, 2020 at 1:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.