Skip to content

Instantly share code, notes, and snippets.

@amomin
Last active October 17, 2015 03:27
Show Gist options
  • Save amomin/0fd0553f2a3518e78424 to your computer and use it in GitHub Desktop.
Save amomin/0fd0553f2a3518e78424 to your computer and use it in GitHub Desktop.
Building 64-bit emacs on Windows

Building 64-bit emacs on Windows

Licensed under CC BY 4.0.

This was actually reasonably straightforward....

Installing msys2

I installed msys2 for performing the build. This was pretty straightforward:

  1. Go to the download page
  2. Run the installer as explained - follow instructions on updating the package manager (pacman)
pacman --needed -Sy bash pacman pacman-mirrors msys2-runtime
(close and restart)
pacman -Su

Download the source

This is explained well here, but in any case it's short:

cd parentdirofwhereyouwantsource
git clone git://git.savannah.gnu.org/emacs.git

This will do a full clone (so it will be quite large) - you are probably happy with a shallow build such as

git clone --depth 1 git://git.sv.gnu.org/emacs.git
#(or)
git ls-remote #(to see a list of remote branches)
git clone --depth 1 --branch emacs-24.4 git://git.sv.gnu.org/emacs.git

Build

Before you do this, have a look at nt/INSTALL in the emacs repository - you might be able to just follow it along. You will have to migrate .dlls (or add some msys dll folders to your path). However, I had trouble building the x64 version by myself; following this guide it was a non-issue.

This is written up very nicely here but I will quote the post in its entirety below.

As a summary, it will install emacs to C:\emacs

Everything below this is quoted verbatim from this reference

Licensed under CC BY 4.0.

The following guidelines described how to compile GNU Emacs with MSYS2/MinGW-w64 combination. Or you may prefer 中文版.

Set up the MSYS2/MinGW-w64 build environment

Download the x86_64 version of MSYS2 in 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-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-libtiff
- mingw-w64-x86_64-giflib
- mingw-w64-x86_64-libpng
- mingw-w64-x86_64-libjpeg-turbo
- mingw-w64-x86_64-librsvg
- 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.sv.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 \
--host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 \
--build=x86_64-w64-mingw32 --with-wide-int --with-jpeg --with-xpm \
--with-png --with-tiff --with-rsvg --with-xml2 --with-gnutls \
--with-xft --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

I have to write this command in this stupid way beacuse sourceforge does not show a long line in code block. Let me know if you have a solution. Thanks. 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 builded the 64-Bit version of GNU Emacs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment