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 ?
m
. So add-lm
to link with it. – Galacto-lm
? seems like not enough. any other libraries I need ? I am working with C++14 – Accomplishedlog2
&log2f
? – Accomplished-lm
after your linker list. – Allies-lm
does not make a difference. I get the same list of errors. – Accomplished-lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice -lpostproc -lm
. is this correct? – Accomplishedglibc
libraries. Can you try to compile a little C program that usesatof
andlog2
? BTW, in my system at least,atof
is not inlibm.a
but inlibc.a
. – Alliesconfigure
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--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. – Ruylebuildscript
run below android-21 using ndk r10e works. Yes. no changes to script – Accomplished