MAC Android Studio报错:ffmpeg集成:cmake/3.6.4111459/bin/cmake with arguments

本文记录了在5G时代背景下,作者自学ffmpeg遇到的编译链接错误问题。在尝试将ffmpeg集成到Android Studio项目中时,遇到了链接库失败的错误。通过调整CMakeLists.txt的位置,最终解决了链接ffmpeg库的问题。
摘要由CSDN通过智能技术生成

记录一下困扰了2天的问题,心好累。。。

5G时代来了,突然对音视频产生了兴趣,准备大干一场,来一个自学成才~

1、编译了ffmpeg

2、配置了NDK环境

3、新建了项目,拷贝了ffmpeg.a文件及头文件

But。。。。AndroidStudio编译报错了:

Build command failed.
Error while executing process Library/Android/sdk/cmake/3.6.4111459/bin/cmake with arguments {--build StudioProject/JackiePlayer/app/.externalNativeBuild/cmake/debug/armeabi-v7a --target native-lib}
[1/1] Linking CXX shared library StudioProject/JackiePlayer/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so
FAILED: : && Library/Android/ndk/android-ndk-r17c/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++  --target=armv7-none-linux-androideabi --gcc-toolchain=/Library/Android/ndk/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64 --sysroot=//Library/Android/ndk/android-ndk-r17c/sysroot -fPIC -isystem //Library/Android/ndk/android-ndk-r17c/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=26 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -std=c++11 -L//StudioProject/JackiePlayer/app/src/main/cpp/libs/armeabi-v7a -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot //Library/Android/ndk/android-ndk-r17c/platforms/android-26/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--exclude-libs,libunwind.a -L//Library/Android/ndk/android-ndk-r17c/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o //StudioProject/JackiePlayer/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so CMakeFiles/native-lib.dir/native-lib.cpp.o  -lavcodec -lavfilter -lavformat -lavutil -lswresample -lswscale -llog -latomic -lm "//Library/Android/ndk/android-ndk-r17c/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_static.a" "//Library/Android/ndk/android-ndk-r17c/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++abi.a" "//Library/Android/ndk/android-ndk-r17c/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libunwind.a" "-ldl" && :
//Library/Android/ndk/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lavcodec
//Library/Android/ndk/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lavfilter
//Library/Android/ndk/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lavformat
//Library/Android/ndk/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lavutil
//Library/Android/ndk/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lswresample
//Library/Android/ndk/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lswscale
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

网上各种找资料,全失败。。。

最后经过一步神级(手欠)操作弄好了!!! 

发现,Android Studio3.3.0上新建项目的时候,CMakeLists.txt是在app/src/main/cpp/目录下的,把它移到app/目录下以后,编译就通过了。。。应该是在编写CMakeLists.txt的时候,里面的变量地址写的不对,移出来就找到了,还是自己粗心了啊!

CMakeLists.txt移出来以后,记得修改app路径下build.gradle里面CMakeLists.txt的路径,如下:

移出之前:

externalNativeBuild {
    cmake {
        path "src/main/cpp/CMakeLists.txt"
    }
}

 

移出之后:

externalNativeBuild {
    cmake {
        path "CMakeLists.txt"
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值