美文网首页
环境搭建之库的编译

环境搭建之库的编译

作者: _jetson_ | 来源:发表于2021-03-28 14:07 被阅读0次

    编译LAME

    在windows中ndk-build来进行编译

    1. 将libmp3lame和include中的文件拷贝到jni目录下
    2. 将所有的.c文件,添加到Android.mk中的LOCAL_SRC_FILES中
    注意要保存好头文件 + lib文件
    
    LOCAL_PATH := $(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_SRC_FILES = ./bitstream.c ./encoder.c ./fft.c ./gain_analysis.c ./id3tag.c ./lame.c ./mpglib_interface.c ./newmdct.c ./presets.c ./psymodel.c ./quantize.c ./quantize_pvt.c ./reservoir.c ./set_get.c ./tables.c ./takehiro.c ./util.c ./vbrquantize.c ./VbrTag.c ./vector/xmm_quantize_sub.c ./version.c
    LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
    LOCAL_MODULE := liblame
    include $(BUILD_SHARED_LIBRARY)
    

    在linux中用ndk-build来编译

    ndk-build配置

    先下载ndk-build:https://developer.android.com/ndk/downloads/index.html
    1. 初始化交叉编译工具链
    (1)得到x86架构的Android Q的ndk-build交叉编译工具链,并放在my-toolchain目录中
    $NDK/build/tools/make_standalone_toolchain.py \
      --arch x86 \
      --api 29 \
      --install-dir=my-toolchain
    (2)设置环境变量
    # Add the standalone toolchain to the search path.
    export PATH=/home/jetson/Documents/android-ndk-r22-linux-x86_64/android-ndk-r22/my-toolchain/bin:$PATH
    
    # Tell configure what tools to use.
    target_host=i686-linux-android
    export AR=$target_host-ar
    export AS=$target_host-clang
    export CC=$target_host-clang
    export CXX=$target_host-clang++
    export LD=$target_host-ld
    export STRIP=$target_host-strip
    
    # Tell configure what flags Android requires.
    export CFLAGS="-fPIE -fPIC"
    export LDFLAGS="-pie"
    

    进行LAME的编译

    (1)配置
    --host为目标编译器的前缀,--disable-shared编译为静态库
    ./configure --disable-shared --disable-frontend --prefix="/home/jetson/Documents/lame-3.100/thin/x86" --host=i686-linux-android
    (2)编译
    make -j8
    最后得到libmp3lame/.libs/libmp3lame.a文件
    

    编译ffmpeg

    在linux中编译使用的

    编译准备

    1. 安装包:
    sudo apt-get install libx11-dev
    sudo apt-get install xorg-dev
    sudo apt-get install yasm : 用来提高ffmpeg的编译速度的
    2. 编译安装SDL
    https://www.libsdl.org/download-2.0.php
    ./configure
    make
    sudo make install
    
    编译完SDL之后,发现使用ffplay命令是没有办法播放音乐的:
    SDL_OpenAudio (2 channels, 44100 Hz): No such audio device
    SDL_OpenAudio (1 channels, 44100 Hz): No such audio device
    No more combinations to try, audio open failed
    
    解决办法:
    sudo apt-get install libasound2-dev
    sudo apt-get install libpulse-dev
    然后重新进行安装:
    sudo make uninstall
    sudo make distclean
    ./configure
    sudo make
    sudo make install
    参考链接:https://www.codenong.com/cs106393555/
    

    进行ffmpeg编译

    1. 安装x264库
    ./configure --enable-shared --enable-static --prefix="/home/jetson/Documents/x264-master/x264_install" && make -j7 && make install
    2. 安装fdk-aac库
    ./configure --enable-shared --enable-static --prefix="/home/jetson/Documents/fdk-aac-2.0.1/fdk_install" && make -j7 && make install
    3. 安装lame
    ./configure --enable-shared --enable-static --prefix="/home/jetson/Documents/lame-3.100/lame_install" && make -j7 && make install
    4. 编译安装ffmpeg
    export PKG_CONFIG_PATH=/home/jetson/Documents/ffmpeg-snapshot/ffmpeg/external-libs/fdk_install/lib/pkgconfig:$PKG_CONFIG_PATH
    
    export PKG_CONFIG_PATH=/home/jetson/Documents/ffmpeg-snapshot/ffmpeg/external-libs/x264_install/lib/pkgconfig:$PKG_CONFIG_PATH
    
    ./configure --enable-shared --enable-static --enable-libx264 --enable-gpl --enable-libfdk-aac --enable-libmp3lame --extra-cflags="-Iexternal-libs/fdk_install/include -Iexternal-libs/lame_install/include -Iexternal-libs/x264_install/include" --extra-ldflags="-Lexternal-libs/fdk_install/lib -Lexternal-libs/lame_install/lib -Lexternal-libs/x264_install/lib" --enable-nonfree --enable-avdevice
    make
    sudo make install
    
    问题:
    ffmpeg: error while loading shared libraries: libfdk-aac.so.2: cannot open shared object file: No such file or directory
    
    只要sudo make install就可以了,不需要上面的external-libs了
    sudo vi /etc/ld.so.conf ,将/usr/local/lib路径直接粘贴进去。
    
    sudo ldconfig ---使上面的配置生效
    
    注:如果ld.so.conf    include的是另外的*.conf 找到这个conf添加进去 保存 (sudo vi /etc/ld.so.conf.d/libc.conf)
    

    在linux中编译成库的

    1. 配置
    ./configure --enable-static --disable-asm --enable-cross-compile --target-os=linux --arch=x86 --cross-prefix=/home/jetson/Documents/android-ndk-r22-linux-x86_64/android-ndk-r22/my-toolchain/bin/i686-linux-android- --prefix="/home/jetson/Documents/ffmpeg-snapshot/ffmpeg/ffmpeg_install" --enable-postproc 
    2. 编译:make -j7
    3. 安装:make install(--prefix就是安装的路径)
    然后库和头文件都安装到指定的路径上了
    要链接的库和头文件,可以使用CFLAGS等环境变量
    编译,最后要库和头文件
    --disable-ffserver
    缩减ffmpeg的大小:
    ./configure --disable-shared --disable-stripping --disable-ffmpeg --disable-ffplay  --disable-ffprobe --disable-avdevice --disable-devices --disable-indevs --disable-outdevs --disable-debug --disable-asm --disable-yasm --disable-doc --disable-filters --disable-postproc --disable-bsfs --disable-encoders --disable-decoders --disable-parsers --disable-muxers --disable-demuxers --disable-protocols --enable-static --enable-small --enable-dct --enable-dwt --enable-lsp --enable-mdct --enable-rdft --enable-fft --enable-version3 --enable-nonfree --enable-bsf=aac_adtstoasc --enable-bsf=h264_mp4toannexb --enable-encoder=pcm_s16le --enable-encoder=aac --enable-encoder=libvo_aacenc --enable-decoder=aac --enable-decoder=mp3 --enable-decoder=pcm_s16le --enable-parser=aac --enable-muxer=flv --enable-muxer=wav --enable-muxer=adts --enable-demuxer=flv --enable-demuxer=wav --enable-demuxer=aac --enable-protocol=rtmp --enable-protocol=file --enable-cross-compile --target-os=linux --arch=x86 --cross-prefix=/home/jetson/Documents/android-ndk-r22-linux-x86_64/android-ndk-r22/my-toolchain/bin/i686-linux-android- --prefix="/home/jetson/Documents/ffmpeg-snapshot/ffmpeg/ffmpeg_install"
    
    问题:
    avformat_open_input:Invalid data found when processing input
    在调用ffmpeg.so库的时候,遇到这个报错,是因为没有将需要的格式编译进来,进行完整编译之后,就不会报错了。
    
    

    编译X264库

    1. 配置
    ./configure --enable-static --disable-asm --enable-pic --host=i686-linux-android
    2. 编译:make -j7
    

    编译fdk-aac库

    1. 配置
    ./configure --enable-static --host=i686-linux-android
    2. 编译:make -j7
    
    错误:
    (1)找不到log.h
    libSBRdec/src/lpp_tran.cpp:122:10: fatal error: 'log.h' file not found
    #include <log.h>
             ^~~~~~~
    1 error generated.
    make: *** [Makefile:1575: libSBRdec/src/lpp_tran.lo] Error 1
    make: *** Waiting for unfinished jobs....
    
    (2)找不到android_errorWriteLog
    libSBRdec/src/lpp_tran.cpp:342:5: error: use of undeclared identifier 'android_errorWriteLog'
        android_errorWriteLog(0x534e4554, "112160868");
        ^
    libSBRdec/src/lpp_tran.cpp:922:5: error: use of undeclared identifier 'android_errorWriteLog'
        android_errorWriteLog(0x534e4554, "112160868");
        ^
      CXX      libFDK/src/mdct.lo
    2 errors generated.
    make: *** [Makefile:1575: libSBRdec/src/lpp_tran.lo] Error 1
    make: *** Waiting for unfinished jobs....
    
    解决办法:删掉即可
    

    相关文章

      网友评论

          本文标题:环境搭建之库的编译

          本文链接:https://www.haomeiwen.com/subject/ytuphltx.html