Difference between revisions of "Win32Compile"

From VideoLAN Wiki
Jump to navigation Jump to search
(Undo revision 30228 by Meshr (talk))
Line 31: Line 31:
 
To compile VLC for Windows (32-bits or 64-bits), the Mingw-w64 toolchain is required:
 
To compile VLC for Windows (32-bits or 64-bits), the Mingw-w64 toolchain is required:
  
* '''Debian/Ubuntu''': run <code>apt-get install gcc-mingw-w64-i686 g++-mingw-w64-i686 mingw-w64-tools automake libtool</code>
+
* '''Debian/Ubuntu''': run <code>apt-get install gcc-mingw-w64-i686 g++-mingw-w64-i686 mingw-w64-tools</code>
For the 64-bit version, this becomes <code>apt-get install gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 mingw-w64-tools automake libtool</code>
+
For the 64-bit version, this becomes <code>apt-get install gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 mingw-w64-tools</code>
  
 
(on Debian you must be on wheezy or above to find this package)
 
(on Debian you must be on wheezy or above to find this package)

Revision as of 23:11, 4 September 2015

This page will help you to compile VLC media player for Windows.

Building Methods

If you want to build VLC from source, you have several choices:

Method Documentation Notes
MinGW on Linux Obtaining the toolchain Preferred method involving cross-compilation from Linux. On computers running Microsoft Windows, a virtual machine is necessary to run Linux.
MSYS+MinGW on Windows Compile with MSys Native compilation method. MSYS is a minimal build environment to compile Unix-style projects directly on Microsoft Windows. This is not officially supported by VideoLAN. Best of luck.
Cygwin on Windows Compile with Cygwin Cygwin method. Cygwin emulates a POSIX environment to compile on Microsoft Windows. This is error-prone and slow and therefore not recommended.

Obtaining the cross-compilation toolchain

Compiler and binary toolchain

Mingw-w64

To compile VLC for Windows (32-bits or 64-bits), the Mingw-w64 toolchain is required:

  • Debian/Ubuntu: run apt-get install gcc-mingw-w64-i686 g++-mingw-w64-i686 mingw-w64-tools

For the 64-bit version, this becomes apt-get install gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 mingw-w64-tools

(on Debian you must be on wheezy or above to find this package)

You might want to use the following script to enforce static compilation. Run as root, and use at your own risk.

#!/bin/sh

# This script enforces statically linking of libgcc, libstdc++-6, and libpthread,
# without needing to rebuild gcc and mingw-w64 from scratch.
# -static-libgcc -static-libstdc++ flags can not be used in a libtool build system,
# as libtool removes flags that it doesn't understand.

move() {
    [ -f $1 ] || return 1
    mkdir -p old/
    mv -v $* old/
    return 0
}

for x in i686 x86_64
do
    library_path_list=`$x-w64-mingw32-gcc -v /dev/null 2>&1 | grep ^LIBRARY_PATH|cut -d= -f2|sort|uniq`
    IFS=':'
    for i in $library_path_list
    do
        cd $i
        move libstdc++-6.dll libstdc++.dll.a libgcc_s.a libgcc_s_sjlj-1.dll && ln -s libgcc_eh.a libgcc_s.a
        move libpthread.dll.a libwinpthread.dll.a
        move libwinpthread-1.dll
        [ -d ../bin ] && cd ../bin && move libwinpthread-1.dll
    done
done

exit 0

Mingw32

Up to versions 2.0.x, VLC was compiled with the older mingw32 toolchain, which only supports 32-bits Windows. If you have problems with mingw-w64, you can try mingw32 instead:

  • Debian/Ubuntu: run apt-get install gcc-mingw32 mingw32-binutils. Note that at least version 3.17 of Mingw32 is required, which Debian does not provide. You may obtain mingw32-runtime-3.17 here.
  • Gentoo users can emerge crossdev && crossdev mingw32
  • ArchLinux users can pacman -S mingw32-gcc
  • Fedora users should read Win32Compile Under Fedora
  • Other Linux systems may attempt http://www.mingw.org/wiki/LinuxCrossMinGW

Development tools

You will also need:

  • lua (5.1 or 5.2)
  • all autotools: libtool, automake, autoconf, autopoint, make, gettext
  • pkg-config
  • qt4-dev-tools, qt5-default
  • git
  • subversion
  • cmake, cvs if you want to rebuild contribs
  • wine-dev for creating Win32 packages
  • zip [for creating .zip package], p7zip [for .7z package], nsis [for .exe auto-installer], bzip2 [for 'make prebuild]

Host triplet

A number of example commands below include the identifier of the toolchain. This value is essential: it instructs the build system to use the correct toolchain and compile the program for Windows. Without the value, the build system will perform a native compilation for Linux (or whatever your computer runs). With an incorrect value, the build will fail.

This is known as the host triplet, although it's more of a pair than a triplet in the case of Mingw. The exact value depends on your installation of the toolchain. Notably on Debian/Ubuntu, these values must be used:

  • i686-w64-mingw32 for Windows 32-bits, using the Mingw-w64 toolchain
  • x86_64-w64-mingw32 for Windows 64-bits, using the Mingw-w64 toolchain
  • i586-mingw32msvc for Windows 32-bits, using the Mingw32 toolchain

Again, you MUST substitute the value in the following command snippets.

Get the source code

$ git clone git://git.videolan.org/vlc.git vlc

See Git for more information.

Go into the VLC directory

$ cd vlc

Prepare 3rd party libraries

Before compiling VLC, you need lots of other libraries. Here is how to get them:

Ubuntu 14.04 LTS Mingw32-w64 toolchain has an issue with accepting explicit PKG_CONFIG_PATH. Patch mentioned in https://bugs.launchpad.net/ubuntu/+source/mingw-w64/+bug/1327242 needs to be applied to /usr/share/pkg-config-crosswrapper

 $ mkdir -p contrib/win32
 $ cd contrib/win32
 $ ../bootstrap --host=i686-w64-mingw32
 $ make prebuilt

or, if you want to compile the contribs yourself and are feeling adventurous and have lots of time to burn,

 # apt-get install subversion yasm cvs cmake
 $ mkdir -p contrib/win32
 $ cd contrib/win32
 $ ../bootstrap --host=i686-w64-mingw32
 $ make fetch
 $ make

Linux 64-bit

If you are on Linux 64-bit, you SHOULD remove some files, or install the lib32 packages (ia32-libs, multilibs, etc...)

 $ rm -f ../i686-w64-mingw32/bin/moc ../i686-w64-mingw32/bin/uic ../i686-w64-mingw32/bin/rcc

Fix your contrib path

If your host triplet is not i686-w64-mingw32 (you are not compiling for Debian or Ubuntu), create a symlink to contribs:

$ ln -sf insert_your_host_triplet_here ../i686-w64-mingw32

So, for example:

$ ln -sf x86_64-w64-mingw32 ../i686-w64-mingw32

Notice that there is no ../ before the host triplet. This is intentional, and if done properly, you should see a functioning symbolic link created in the parent directory (try ls -l .. and you should see i686-w64-mingw32 -> x86_64-w64-mingw32/).

Go Back

Go back to the VLC source directory:

 $ cd -

Configuring the build

Bootstrap

First, prepare the tree:

 $ ./bootstrap

Configure

Then you can to configure the build with the ./configure script.

Create a subfolder:

 $ mkdir win32 && cd win32

Set your PKG_CONFIG_LIBDIR

 $ export PKG_CONFIG_LIBDIR=$HOME/vlc/contrib/i686-w64-mingw32/lib/pkgconfig

Use the standard configuration:

$ ../extras/package/win32/configure.sh --host=i686-w64-mingw32

NB: use YOUR cross-compiling prefix here, like i486-mingw32

Also, if you have a problem here (such as an error about Library dvdread), see the Talk page.

Alternatively, you can run configure manually:

$ ../configure --host=i686-w64-mingw32

See '../configure --help' for more information.

Building VLC

Once configured, to build VLC, just run:

 $ make

Packaging VLC

Once the compilation is done, you can build self-contained VLC packages with the following make rules:

Command Description
make package-win-common Creates a subdirectory named vlc-x.x.x with all the binaries. You can run VLC directly from this directory.
make package-win-strip Same as above but will create 'stripped' binaries (that is, smallest size, unusable with a debugger).
make package-win32-7zip Same as above but will package the directory in a 7z file.
make package-win32-zip Same as above but will package the directory in a zip file.
make package-win32 Same as above but will also create an auto-installer package. You must have NSIS installed in its default location for this to work.

Well done—you're ready to use VLC!