将libavdevice.a链接到libffmpeg.so时找不到NDK摄像头和媒体原生API符号
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将libavdevice.a链接到libffmpeg.so时找不到NDK摄像头和媒体原生API符号相关的知识,希望对你有一定的参考价值。
我正在使用NDK工具来构建将在我的android rtsp项目中使用的ffmpeg共享库。所有需要的组件都被编译/链接为单独的静态库,最后这些库将作为单个共享库链接。 除了最后一步,一切顺利。链接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
答案
您的…-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不兼容。
以上是关于将libavdevice.a链接到libffmpeg.so时找不到NDK摄像头和媒体原生API符号的主要内容,如果未能解决你的问题,请参考以下文章