Menu

Build guideline for MSYS2-MinGW-w64 system

Licensed under CC BY 4.0.

The following guidelines described how to compile GNU Emacs with MSYS2/MinGW-w64 combination. 中文版看这里. The official repository now has an INSTALL.W64 document based on this guideline.

Set up the MSYS2/MinGW-w64 build environment

Download the x86_64 version of MSYS2 here, and install in your preferred directory, e.g. C:\msys64. Note that path containing spaces may causes problems. Run msys2_shell.bat in the C:\msys64 and you will see a BASH window opened. In the BASH prompt, use the following commands to install the necessary packages:

pacman -S base-devel mingw-w64-x86_64-toolchain \
mingw-w64-x86_64-xpm-nox mingw-w64-x86_64-libtiff \
mingw-w64-x86_64-giflib mingw-w64-x86_64-jbigkit \
mingw-w64-x86_64-libpng mingw-w64-x86_64-libjpeg-turbo \
mingw-w64-x86_64-librsvg mingw-w64-x86_64-libxml2 \
mingw-w64-x86_64-gnutls

These packages are:
Build required package
+ base-devel
- mingw-w64-x86_64-toolchain
- Optional:
- For various image formats
- mingw-w64-x86_64-giflib
- mingw-w64-x86_64-jbigkit
- mingw-w64-x86_64-libjpeg-turbo
- mingw-w64-x86_64-libpng
- mingw-w64-x86_64-librsvg
- mingw-w64-x86_64-libtiff
- For libxml2
- mingw-w64-x86_64-libxml2
- For GnuTLS
- mingw-w64-x86_64-gnutls

Get the source code

Since Emacs's development has finally migrated from Bazaar to Git, you can get Emacs's source code with the following two lines.

pacman -S git
git clone git://git.savannah.gnu.org/emacs.git

The first line installs Git and the second line get the code. For more information, read the quick start guide from EmacsWiki. Or you can download the release version from gnu ftp. It should be pointed that the the autocrlf feature of Git may mess up the configure file. Therefore it is better to disable this feature by running the command:

git config core.autocrlf false

configure; make; make install

Run mingw64_shell.bat in C:\msys64. This will open a BASH window for MinGW-w64 environment. In the BASH prompt, chdir to the directory of source code. Then run the following commands to build Emacs and install it in C:\emacs. If you are building the development version, the first line of the commands is needed.

./autogen.sh
PKG_CONFIG_PATH=/mingw64/lib/pkgconfig ./configure --without-imagemagick
make
make install prefix=/c/emacs

Note that I disable imagemagick because Emacs does not support it in Windows.

If all of the above are successfully done, you should have an Emacs installed in C:\emacs. However, it may not work properly since it depends on DLLs in the MinGW-w64 environment. I use the following command to make sure the DLLs are placed with the execution file:

cp /mingw64/bin/{libwinpthread-*.dll,libXpm-noX*.dll,libdbus-*.dll} /c/emacs/bin
cp /mingw64/bin/{libgomp-*.dll,libgcc_s_seh-*.dll,libglib-*.dll} /c/emacs/bin
cp /mingw64/bin/{libintl-*.dll,libiconv-*.dll,libgobject-*.dll} /c/emacs/bin
cp /mingw64/bin/{libffi-*.dll,libgdk_pixbuf-*.dll,libgio-*.dll} /c/emacs/bin
cp /mingw64/bin/{libgmodule-*.dll,zlib*.dll,librsvg-*.dll} /c/emacs/bin
cp /mingw64/bin/{libcairo-*.dll,libcroco-*.dll,libpango-*.dll} /c/emacs/bin
cp /mingw64/bin/{libpangocairo-*.dll,libxml2-*.dll,libfontconfig-*.dll} /c/emacs/bin
cp /mingw64/bin/{libfreetype-*.dll,libpixman-*.dll,libpng*.dll} /c/emacs/bin
cp /mingw64/bin/{libpangoft*.dll,libpangowin32-*.dll,liblzma-*.dll} /c/emacs/bin
cp /mingw64/bin/{libexpat-*.dll,libharfbuzz-*.dll,libgnutls-*.dll} /c/emacs/bin
cp /mingw64/bin/{libgnutlsxx-*.dll,libtiff-*.dll,libtiffxx-*.dll} /c/emacs/bin
cp /mingw64/bin/{libjpeg-*.dll,libgif-*.dll,libbz2-*.dll,libjbig-*.dll} /c/emacs/bin
cp /mingw64/bin/{libgmp-*.dll,libhogweed-*.dll,libnettle-*.dll} /c/emacs/bin
cp /mingw64/bin/{libp11-kit-*.dll,libtasn1-*.dll} /c/emacs/bin

If you only run Emacs in your PC and your MinGW-w64 binary folder (e.g. C:\msys64\mingw64\bin) is in PATH the above copy step can be optional.

Run

Double click the runemacs.exe in C:\emacs\bin. If no errors occur, you have successfully built the 64-Bit version of GNU Emacs.