Windows

Windows is fully supported as target and as host. Native development is harder than cross compilation, though.

Instructions regarding Windows Phone support moved in a stand-alone page.

Native development

By using ./configure --enable-shared when configuring Libav, you can build all libraries as DLLs.

Msys2

MSYS2 provides multiple environments, its native MSYS one, using their own posix abstraction and the MingGW-w64 ones.

Only MingGW-w64 is supported.

Make sure to use mingw64_shell.bat or mingw32_shell.bat to have the correct MinGW-w64 environment. The default install provides shortcuts to them under MinGW-w64 Win64 Shell and MinGW-w64 Win32 Shell.

Msys2 provides all the needed packages through its manager:

# standard msys packages
pacman -S make diffutils pkgconf git

# mingw-w64 toolchain
pacman -S mingw-w64-x86_64-yasm mingw-w64-x86_64-gcc mingw-w64-x86_64-SDL

From Libav12 the platform is fully recognized, the previous version should explicitly set the target-os.

./configure --target-os=mingw32

make

To target 32bit replace the x86_64 with i686 in the command above.

Microsoft Visual C++ or Intel C++ Compiler for Windows

Libav can be built with MSVC 2012 or earlier using a C99-to-C89 conversion utility and wrapper, or with MSVC 2013 and ICL natively.

Microsoft Visual Studio Express works fine in wine thus making possible to compile on Linux using this compiler.

You will need the following prerequisites:

To set up a proper environment in MSYS, you need to run msys_shell.bat from the Visual Studio or Intel Compiler command prompt.

Place yasm.exe somewhere in your PATH. If using MSVC 2012 or earlier, place c99wrap.exe and c99conv.exe somewhere in your PATH as well.

Next, make sure any other headers and libs you want to use, such as zlib, are located in a spot that the compiler can see. Do so by modifying the LIB and INCLUDE environment variables to include the Windows-style paths to these directories. Alternatively, you can try and use the --extra-cflags/--extra-ldflags configure options. If using MSVC 2012 or earlier, place inttypes.h somewhere the compiler can see too.

Finally, run:

# For MSVC:
./configure --toolchain=msvc

# For ICL:
./configure --toolchain=icl

make
make install

If you wish to compile shared libraries, add --enable-shared to your configure options. Note that due to the way MSVC and ICL handle DLL imports and exports, you cannot compile static and shared libraries at the same time, and enabling shared libraries will automatically disable the static ones.

If you wish to build with zlib support, you will have to grab a compatible zlib binary from somewhere, with an MSVC import lib, or if you wish to link statically, you can follow the instructions below to build a compatible zlib.lib with MSVC. Regardless of which method you use, you must still follow step 3, or compilation will fail.

  1. Grab the zlib sources.
  2. Edit win32/Makefile.msc so that it uses -MT instead of -MD, since this is how Libav is built as well.

  3. Edit zconf.h and remove its inclusion of unistd.h. This gets erroneously included when building Libav.

  4. Run nmake -f win32/Makefile.msc.

  5. Move zlib.lib, zconf.h, and zlib.h to somewhere MSVC can see.

Libav has been tested with the following on i686 and x86_64:

  • Visual Studio 2010 Pro and Express
  • Visual Studio 2012 Pro and Express
  • Visual Studio 2013 Pro and Express
  • Intel Composer XE 2013
  • Intel Composer XE 2013 SP1
  • Anything else is not officially supported.

Linking to Libav with Microsoft Visual C++

If you plan to link with MSVC-built static libraries, you will need to make sure you have Runtime Library set to Multi-threaded (/MT) in your project’s settings.

You will need to define inline to something MSVC understands:

#define inline __inline

Also note, that as stated in Microsoft Visual C++, you will need an MSVC-compatible inttypes.h.

If you plan on using import libraries created by dlltool, you must set References to No (/OPT:NOREF) under the linker optimization settings, otherwise the resulting binaries will fail during runtime. This is not required when using import libraries generated by lib.exe. This issue is reported upstream at sourceware.org/bugzilla.

To create import libraries that work with the /OPT:REF option (which is enabled by default in Release mode), follow these steps:

  1. Open the Visual Studio Command Prompt.
    • Alternatively, in a normal command line prompt, call ‘vcvars32.bat’ which sets up the environment variables for the Visual C++ tools (the standard location for this file is something like ‘C:\Program Files (x86_\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat’).
  2. Enter the ‘bin’ directory where the created LIB and DLL files are stored.
  3. Generate new import libraries with lib.exe:

lib /machine:i386 /def:..\lib\foo-version.def  /out:foo.lib

You might need to pass --sysroot= to point to the correct cross root if you want to use optional libraries already cross compiled.

Msys

Libav build system requires a working posix shell and gnumake, they are normally available through the cygwin or the msys distributions.

Once the posix shell environment is available the standard configure invocation can be used to build using the provided gcc. The native compiler, msvc is also supported.

Libav can be built to run natively on Windows using the MinGW or MinGW-w64 toolchains. Install the latest versions of MSYS and MinGW or MinGW-w64.

Building natively using MSYS can be sped up by disabling implicit rules in the Makefile by calling make -r instead of plain make. This speed up is close to non-existent for normal one-off builds and is only noticeable when running make for a second time (for example during make install).

In order to compile avplay, you must have the MinGW development library of SDL and pkg-config installed.

Cross compilation

Most linux distributions provide mingw-w64 out of box.

# debian and derivatives
apt-get install mingw-w64
# gentoo and derivatives
emerge crossdev
crossdev x86_64-w64-mingw32

Building

Libav supports cross compilation through configure

./configure --enable-cross-compile --enable-w32threads --prefix=/usr --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32

Cross compilation for Windows with Linux

MingGW

The mingw-w64 project provides up to date toolchains for windows.

Then configure Libav with the following options:

./configure --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --sysroot=/usr/x86_64-w64-mingw32/

Useful options:

  • It is warmly advised to add --extra-ldflags=-static-libgcc not not require to carry the separate dll for the gcc runtime.

  • You can easily test Libav with Wine by passing --target-exec=wine to the configure line.

MSVC

It is possible to run the visual-studio compiler under wine and have it build Libav using the --toolchain=msvc as explained above.

Caveats:

  • The cl.exe requires a proper environment set up.

  • You must pass --disable-debug since the linker otherwise would misbehave.

Compilation under Cygwin

Please use Cygwin 1.7.x as the obsolete 1.5.x Cygwin versions lack llrint() in its C library.

Install your Cygwin with all the "Base" packages, plus the following "Devel" ones:

binutils, gcc4-core, make, git, mingw-runtime, texi2html

In order to run FATE you will also need the following "Utils" packages:

bc, diffutils

If you want to build Libav with additional libraries, download Cygwin "Devel" packages for Ogg and Vorbis from any Cygwin packages repository:

libogg-devel, libvorbis-devel

These library packages are only available from Cygwin Ports:

yasm, libSDL-devel, libfaac-devel, libgsm-devel, libmp3lame-devel,
libschroedinger1.0-devel, speex-devel, libtheora-devel, libxvidcore-devel

The recommendation for x264 is to build it from source, as it evolves too quickly for Cygwin Ports to be up to date.

Crosscompilation for Windows under Cygwin

With Cygwin you can create Windows binaries that do not need the cygwin1.dll.

Just install your Cygwin as explained before, plus these additional "Devel" packages:

gcc-mingw-core, mingw-runtime, mingw-zlib

and add some special flags to your configure invocation.

For a static build run

./configure --target-os=mingw32 --extra-cflags=-mno-cygwin --extra-libs=-mno-cygwin

and for a build with shared libraries

./configure --target-os=mingw32 --enable-shared --disable-static --extra-cflags=-mno-cygwin --extra-libs=-mno-cygwin


CategoryWIP