MDN wants to learn about developers like you:

Cross Compile Mozilla for Mingw32

This document describes how to build Mozilla for Windows using Linux as a development platform. Although this article only specifically covers building Firefox, the same technique can be used to build any Mozilla project, such as Thunderbird.

Making a cross-compiler and compiling Mozilla is necessary before you can run a static analysis on Windows specific code.

Build a GCC mingw cross-compiler


  • GNU Binutils 2.23.1 is required. Older versions will not work.
  • GCC 4.9.0 is used as the GCC version. Any version newer than 4.5.1 should work.
  • mingw-w64, preferably trunk version, is required. Besides what the name suggests, it's a mingw fork supporting both 32 and 64-bit targets. We need this fork because it's currently much better than plain mingw and contains many fixes required for building Firefox. Mozilla code base often adds new headers and libraries dependences that are not present in mingw-w64. Those are usually quickly fixed upstream. That's why it's best to use trunk version to make sure all such fixes are present.

Following commands will ensure that all required packages are available:

$ mkdir $HOME/mingw-w64-build
$ cd $HOME/mingw-w64-build
$ wget
$ tar -jxf binutils-2.24.tar.bz2
$ wget
$ tar -jxf gcc-4.9.0.tar.bz2
$ git clone git://

Build Binutils

First, cross compile the binutils:

$ mkdir binutils-2.24-build32 && cd binutils-2.24-build32
$ ../binutils-2.24/configure --prefix=/usr/local/ --target=i686-w64-mingw32
$ make
# make install

After the binutils are installed, there are several directories under the /usr/local directory. Among them is a bin/ directory for binaries, including i686-w64-mingw32-as, i686-w64-mingw32-ld, and so forth. Note that you may replace /usr/local with your preferred location (you have to use the same location through whole the instructions). Make sure that your $PREFIX/bin directory is in the PATH in this case.

Install mingw-w64-headers

Now, we need to install mingw headers to the right place.

$ mkdir mingw-w64-headers32 && cd mingw-w64-headers32
$ ../mingw-w64/mingw-w64-headers/configure --host=i686-w64-mingw32 --prefix=/usr/local/i686-w64-mingw32/ --enable-sdk=all --enable-secure-api --enable-idl
# make install

Build GCC itself

Now we can configure and build GCC.

$ mkdir gcc-4.9.0-mingw32 && cd gcc-4.9.0-mingw32
$ ../gcc-4.9.0/configure --prefix=/usr/local/ --target=i686-w64-mingw32 --with-gnu-ld --with-gnu-as --enable-languages=c,c++ --disable-multilib
$ make all-gcc
# make install-gcc

After GCC is installed, there are more binaries in /usr/local/bin. But now, we did not have a complete GCC.

Install mingw-w64-crt

We need to install mingw-w64 crt package now:

$ mkdir mingw-w64-crt32 && cd mingw-w64-crt32
$ ../mingw-w64/mingw-w64-crt/configure --host=i686-w64-mingw32 --prefix=/usr/local/i686-w64-mingw32/
$ make
# make install

Finish GCC install

Now that we have crt installed, we may finish building GCC:

$ cd gcc-4.9.0-mingw32
$ make
# make install

Install widl (optional)

widl is an IDL compiler, a replacement for Microsoft's MIDL, developed by Wine project and provided by mingw-w64. This is required for building accessibility modules of Mozilla. You may skip this step and add --disable-accessibility to your mozconfig instead.

$ mkdir widl32
$ ../mingw-w64/mingw-w64-tools/widl/configure --prefix=/usr/local --target=i686-w64-mingw32
$ make
# make install

Configure Mozilla

You can get the source code following the instructions at here. After you have the source, create a .mozconfig file at the top level source directory.

Here's an example .mozconfig file:

#Specify the cross compile
ac_add_options --enable-application=browser
ac_add_options --target=i686-w64-mingw32
ac_add_options --enable-default-toolkit=cairo-windows
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/../mozilla-mingw

ac_add_options  --enable-debug
ac_add_options  --disable-optimize

ac_add_options --disable-crashreporter
ac_add_options --disable-maintenance-service
ac_add_options --disable-webrtc
ac_add_options --without-intl-api
ac_add_options --disable-sandbox

# ac_add_options --disable-accessibility # uncomment if you don't have widl installed

# Use parallel build. Adjust number of processes for your setup.
mk_add_options MOZ_MAKE_FLAGS=-j8


Build it:

./mach build

It's likely that the build will fail for you. That's because mingw builds are considered Tier-3, meaning that they are not guaranteed any to work on plain tree all the time. Such problems are usually fixed quickly. You may search Bugzilla for bugs containing a patch that is on its way to mozilla-central. Also, sometimes a fix to mingw-w64 is required. Make sure you use recent trunk version in such case. Updating Git tree and reinstalling mingw-w64 headers and crt packages (see above) should be enough in this case, there is no need to reinstall whole GCC and binutils packages.

64-bit builds

To compile 64-bit version of Mozilla, the steps are almost identical. Replace i686-w64-mingw32 with x86_64-w64-mingw32 for host/target options in above instruction to build the toolchain and modify mozconfig to build 64-bit Mozilla.


How can I debug the result Firefox?

You can use Mingw's GDB to debug the result Firefox on Windows machine. Download it from here.

You also need to download Mozilla source code to your debug machine to make source level debugging.


Why the build system not take my i686-w64-mingw32-gcc as a cross-compiler?

The configure script used to determine whether a compiler is a cross compiler use the following method: it compile a simple c program and then execute it in the shell. If the result program is runnable, the configure system this the compiler is not a cross compiler. But in some Ubuntu Linux, after you have installed wine, you can run Windows executable directly in your shell. And this fails the configure test...


Other troubles

Please ask in the newsgroup

Document Tags and Contributors

 Contributors to this page: teoli, jacek, Ehsan, David.humphrey, Tglek, Techrazy, Sheppy, bsmedberg
 Last updated by: jacek,