我正在使用NDK工具构建ffmpeg共享库,该库将用于我的
android rtsp项目。所有需要的组件都作为单独的文件进行编译/链接
静态库,最后这些库将作为单个共享库链接。
除了最后一步,一切都进行顺利。链接时发生错误
libavdevice,找不到NDK相机和媒体中的所有符号,错误
日志:
libavdevice/android_camera.c:702: error: undefined reference
to 'ACameraCaptureSession_stopRepeating'
libavdevice/android_camera.c:706: error: undefined reference
to 'ACameraCaptureSession_close'
libavdevice/android_camera.c:711: error: undefined reference
to 'ACaptureRequest_removeTarget'
libavdevice/android_camera.c:712: error: undefined reference
to 'ACaptureRequest_free'
libavdevice/android_camera.c:717: error: undefined reference
to 'ACameraOutputTarget_free'
libavdevice/android_camera.c:722: error: undefined reference
to 'ACaptureSessionOutputContainer_remove'
libavdevice/android_camera.c:724: error: undefined reference
to 'ACaptureSessionOutput_free'
libavdevice/android_camera.c:729: error: undefined reference
to 'ANativeWindow_release'
libavdevice/android_camera.c:734: error: undefined reference
to 'ACaptureSessionOutputContainer_free'
libavdevice/android_camera.c:739: error: undefined reference
to 'ACameraDevice_close'
libavdevice/android_camera.c:744: error: undefined reference
to 'AImageReader_delete'
libavdevice/android_camera.c:749: error: undefined reference
to 'ACameraMetadata_free'
libavdevice/android_camera.c:756: error: undefined reference
to 'ACameraManager_delete'
libavdevice/android_camera.c:172: error: undefined reference
to 'ACameraDevice_getId'
libavdevice/android_camera.c:163: error: undefined reference
to 'ACameraDevice_getId'
libavdevice/android_camera.c:392: error: undefined reference
to 'AImageReader_acquireLatestImage'
libavdevice/android_camera.c:483: error: undefined reference
to 'AImage_delete'
libavdevice/android_camera.c:345: error: undefined reference
to 'AImage_getPlanePixelStride'
libavdevice/android_camera.c:346: error: undefined reference
to 'AImage_getPlaneData'
...
这是在Windows 7 x86_64 PC上运行的构建脚本。
#!/bin/bash
export TMPDIR=D:/other/AndroidDevelopment/ffmpeg-4.0.2/ffmpegtemp
NDK=D:/software/app/android_sdk/ndk-bundle
SYSROOT=$NDK/platforms/android-28/arch-x86_64/
TOOLCHAIN=$NDK/toolchains/x86_64-4.9/prebuilt/windows-x86_64
CPU=x86_64
PREFIX=./android/$CPU
function build_one
{
./configure \
--prefix=$PREFIX \
--enable-static \
--enable-jni \
--enable-pthreads \
--enable-mediacodec \
--disable-asm \
--disable-shared \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-doc \
--disable-symver \
--cross-prefix=$TOOLCHAIN/bin/x86_64-linux-android- \
--target-os=android \
--arch=x86_64 \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags=" -isysroot $NDK/sysroot -I$NDK/sysroot/usr/include/x86_64-linux-android" \
--extra-ldflags=-pie
make clean
make -j4
make install
$TOOLCHAIN/bin/x86_64-linux-android-ld \
-rpath-link=$SYSROOT/usr/lib64 \
-L$SYSROOT/usr/lib64 \
-L$PREFIX/lib \
-soname libffmpeg.so -shared -nostdlib -Bsymbolic --whole-archive --no- undefined -o \
$PREFIX/libffmpeg.so \
libavcodec/libavcodec.a \
libavfilter/libavfilter.a \
libswresample/libswresample.a \
libavformat/libavformat.a \
libavutil/libavutil.a \
libswscale/libswscale.a \
libavdevice/libavdevice.a \
-lc -lm -lz -ldl -llog --dynamic-linker=/system/bin/linker \
$TOOLCHAIN/lib/gcc/x86_64-linux-android/4.9.x/libgcc.a \
}
build_one
答案 0 :(得分:1)
您的…-ld
命令需要对Android本机库的显式引用:
-lcamera2ndk -lmediandk -lnativewindow
实际上,我不理解对build_one
shell函数的这种痴迷。这是NDK r18b2和ffmpeg 4.0.2最适合我的最小脚本:
export NDK=whatever
export CPU=x86_64
export CROSS=$NDK/toolchains/$CPU-4.9/prebuilt/darwin-x86_64/bin/$CPU-linux-android-
mkdir android_$CPU
cd android_$CPU
../configure --enable-static --enable-jni --enable-pthreads --enable-mediacodec \
--disable-asm --disable-shared --disable-doc --disable-ffmpeg --disable-ffplay \
--disable-ffprobe --disable-doc --disable-symver \
--cross-prefix=$CROSS --target-os=android --arch=$CPU --enable-cross-compile \
--sysroot=$NDK/platforms/android-28/arch-$CPU \
--extra-cflags="-isysroot $NDK/sysroot -I $NDK/sysroot/usr/include -I $NDK/sysroot/usr/include/$CPU-linux-android" \
--extra-ldflags="-pie -L$NDK/platforms/android-28/arch-$CPU/usr/lib64 -lc -lm" \
--ld=$CROSS-ld
make CONFIG_V4L2_OUTDEV=no
$CROSS-ld -soname libffmpeg.so -shared -nostdlib -Bsymbolic \
--whole-archive --no-undefined -o libffmpeg.so \
libavcodec/libavcodec.a libavfilter/libavfilter.a \
libswresample/libswresample.a libavformat/libavformat.a \
libavutil/libavutil.a libswscale/libswscale.a libavdevice/libavdevice.a \
-L$NDK/platforms/android-28/arch-$CPU/usr/lib64 \
-lc -lm -lz -lcamera2ndk -lmediandk -lnativewindow
请注意,我禁用了 v4l2输出。 libavdevice / v4l2.c 的编译失败,因为 ioctl()的NDK定义与 ffmpeg 不兼容。