有个问题是Lunix的编译版本和androidstudio的NDK版本最好一致
编译环境
ARM:
export mygcc=/home/zchw/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
X86:
export ix86="/root/android-ndk-r17b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc"
ARM64:
export myArm64="/home/zchw/android-ndk-r17c/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-gcc"
编译引用文件路径
ARM:
export hello="--sysroot=/home/zchw/android-ndk-r17c/platforms/android-21/arch-arm -isystem /home/zchw/android-ndk-r17c/sysroot/usr/include -isystem /home/zchw/android-ndk-r17c/sysroot/usr/include/arm-linux-androideabi"
X86:
export hello86="--sysroot=/home/zchw/android-ndk-r17c/platforms/android-21/arch-x86 -isystem /home/zchw/android-ndk-r17c/sysroot/usr/include -isystem /home/zchw/android-ndk-r17c/sysroot/usr/include/i686-linux-android"
ARM64:
export hello64="--sysroot=/home/zchw/android-ndk-r17c/platforms/android-21/arch-arm64 -isystem /home/zchw/android-ndk-r17c/sysroot/usr/include -isystem /home/zchw/android-ndk-r17c/sysroot/usr/include/aarch64-linux-android"
hello -pie main.c -o main
// -pie与位置无关,编译可执行文件
//-fPIC给动态库使用,编译动态库
file main 查看编译后文件类型
编译动态库
$mygcc $hello -fPIC -shared test.c -o libTest.so
$ix86 $hello86 -fPIC -shared test.c -o libTest.so
$myArm64 $hello64 -fPIC -shared test.c -o libTest.so
查看动态库里面的方法 cmd
D:\adt\SDK\ndk-bundle\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin\arm-linux-androideabi-nm.exe C:\Users\zchw\Desktop\libTest.so
tar包解压
tar xvf ffmpeg-4.1.5.tar.bz2
解包:tar xvf FileName.tar
打包:tar cvf FileName.tar DirName
多个库编程so
--sysroot=/root/android-ndk-r17b/platforms/android-21/arch-arm/ -shared -o libffmpeg.so -wl,--whole-archive libavcodec.a lib avformat.a libavutil.a libswresample.a libswscale.a libavfilter.a -wl,--no-whole-archive
Message输出文件
build_output.txt
sudo mv 'android-ndk-r19c-linux-x86_64.zip?hl=zh_cn' zchw
查看依赖
ndk-bundle / ndk-depends查看依赖
cmd
ndk-bundle\ndk-depends.cmd xxx.so
/home/zchw/android-ndk-r19c/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin
网友评论