Windows下在编译前需要修改环境变量,确保有这两个变量 INCLUDE 以及 PKG_CONFIG_PATH
除此之外,我们还对编出来的库有些其它要求,例如,库名中不能有版本号相关的信息,
修改configure
win32|win64)
disable symver
if enabled shared; then
# Link to the import library instead of the normal static library
# for shared libs.
LD_LIB='%.lib'
# Cannot build both shared and static libs with MSVC or icl.
disable static
fi
enabled x86_32 && check_ldflags -LARGEADDRESSAWARE
shlibdir_default="$bindir_default"
SLIBPREF=""
SLIBSUF=".dll"
SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
SLIB_CREATE_DEF_CMD='EXTERN_PREFIX="$(EXTERN_PREFIX)" $(SRC_PATH)/compat/windows/makedef $(SUBDIR)lib$(NAME).ver $(OBJS) > $$(@:$(SLIBSUF)=.def)'
SLIB_INSTALL_NAME='$(SLIBNAME)' # 修改为SLIBNAME
SLIB_INSTALL_LINKS=
SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)' # 修改为 SLIBNAME
SLIB_INSTALL_EXTRA_LIB='$(SLIBNAME:$(SLIBSUF)=.def)'
SHFLAGS='-dll -def:$$(@:$(SLIBSUF)=.def) -implib:$(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib)' #
enabled x86_64 && objformat="win64" || objformat="win32"
ranlib=:
enable dos_paths
add_extralibs -lole32
add_extralibs -ladvapi32
;;
修改ffbuild\library.mak
$(SUBDIR)lib$(NAME).ver: $(SUBDIR)lib$(NAME).v $(OBJS)
$$(M)sed 's/MAJOR/$(lib$(NAME)_VERSION_MAJOR)/' $$< | $(VERSION_SCRIPT_POSTPROCESS_CMD) > $$@
## $(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(SUBDIR)$(SLIBNAME_WITH_MAJOR)
## echo "$(Q)cd ./$(SUBDIR) && $(LN_S) $(SLIBNAME_WITH_MAJOR) $(SLIBNAME)"
$(SUBDIR)$(SLIBNAME): $(OBJS) $(SLIBOBJS) $(SUBDIR)lib$(NAME).ver
$(SLIB_CREATE_DEF_CMD)
$$(LD) $(SHFLAGS) $(LDFLAGS) $(LDSOFLAGS) $$(LD_O) $$(filter %.o,$$^) $(FFEXTRALIBS)
$(SLIB_EXTRA_CMD)
ifdef SUBDIR
# $(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(DEP_LIBS)
$(SUBDIR)$(SLIBNAME): $(DEP_LIBS)
endif
还需要保留库里面的符号信息,修改ffbuild\library.mak
install-lib$(NAME)-shared: $(SUBDIR)$(SLIBNAME)
$(Q)mkdir -p "$(SHLIBDIR)"
$$(INSTALL) -m 755 $$< "$(SHLIBDIR)/$(SLIB_INSTALL_NAME)"
# 注释下该行 $$(STRIP) "$(SHLIBDIR)/$(SLIB_INSTALL_NAME)"
$(Q)$(foreach F,$(SLIB_INSTALL_LINKS),(cd "$(SHLIBDIR)" && $(LN_S) $(SLIB_INSTALL_NAME) $(F));)
$(if $(SLIB_INSTALL_EXTRA_SHLIB),$$(INSTALL) -m 644 $(SLIB_INSTALL_EXTRA_SHLIB:%=$(SUBDIR)%) "$(SHLIBDIR)")
$(if $(SLIB_INSTALL_EXTRA_LIB),$(Q)mkdir -p "$(LIBDIR)")
$(if $(SLIB_INSTALL_EXTRA_LIB),$$(INSTALL) -m 644 $(SLIB_INSTALL_EXTRA_LIB:%=$(SUBDIR)%) "$(LIBDIR)")
由于zip_decoder.c需要依赖zlib库,我们需要将包含有函数符号信息的zlib.lib文件存放到根目录下,不然将编译不通过
Windows编译64位FFmpeg脚本:
echo "Start Configure"
echo "./configure --toolchain=msvc --disable-static --disable-programs --enable-shared --disable-devices --disable-filters --disable-protocols --disable-demuxers --disable-muxers --disable-decoders --disable-autodetect --disable-encoders --enable-decoder=h264 --enable-decoder=mjpeg --disable-parsers --enable-parser=h264 --enable-parser=mjpeg --disable-stripping --disable-x86asm --disable-iconv --disable-pthreads --enable-w32threads --extra-ldflags=zlib.lib --prefix=./build/build-x64-windows/"
./configure --toolchain=msvc --disable-static --disable-programs --enable-shared --disable-devices --disable-filters --disable-protocols --disable-demuxers --disable-muxers --disable-decoders --disable-autodetect --disable-encoders --enable-decoder=h264 --enable-decoder=mjpeg --disable-parsers --enable-parser=h264 --enable-parser=mjpeg --disable-stripping --disable-x86asm --disable-iconv --disable-pthreads --enable-w32threads --extra-ldflags=zlib.lib --prefix=./build/build-x64-windows/
if [ $? != 0 ]
then
exit $?
fi
sed -i "s/HAVE_SCHED_GETAFFINITY *1/HAVE_SCHED_GETAFFINITY 0/" config.h
echo "Configure Finished"
echo "Start Make"
make clean
make -j4
echo "Start Make Install"
make install
cp libav*/*.pdb ./build/build-x64-windows/pdb/
cp libsw*/*.pdb ./build/build-x64-windows/pdb/
echo "Make Install Finished"
最后FFmpeg在生成动态库后,还需要把zlib.dll放进去,否则编译出来的程序运行不起来
32位的库类似,如果需要添加对ffplay的支持的话,需要修改configure的配置项如下:
./configure --toolchain=msvc --disable-static --disable-ffmpeg --disable-ffprobe --enable-shared --enable-sdl2 --enable-ffplay --disable-devices --disable-filters --disable-protocols --disable-demuxers --disable-muxers --disable-decoders --disable-autodetect --disable-encoders --enable-decoder=h264 --enable-decoder=mjpeg --disable-parsers --enable-parser=h264 --enable-parser=mjpeg --disable-stripping --disable-x86asm --disable-iconv --disable-pthreads --enable-w32threads --extra-ldflags=SDL2.lib --extra-ldflags=SDL2main.lib --extra-ldflags=zlib.lib --prefix=./build/build-x86-windows/
标签:enable,SLIB,FFmpeg,Windows,SLIBNAME,编译,disable,INSTALL,--
From: https://www.cnblogs.com/siberiawind/p/17675341.html