Compiling Praat for Windows (XP, 7)

Compiling Praat for Windows (XP, 7)

DISCLAIMER

Following these instructions could render your computer unfunctional. It also might destroy data stored on your computer or make data inaccessible.

THESE INSTRUCTIONS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE INSTRUCTIONS IS WITH YOU. SHOULD THE INSTRUCTIONS PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

Introduction

From version 5.2.38, Praat sources can be compiled out-of-the-box for Windows using the MinGW compiling suit. To compile Praat, first install MinGW. Then download all the header files and libraries and move them to the include and lib directories of MinGW.

Preparing the Praat source: 5.2.42 and higher

Download the latest Praat sources from http://www.praat.org/download_sources.html. Unpack the sources and place them in a convenient place.

Go to the top level directory of the Praat sources. Copy the file makefile.defs.mingw32 from the subdirectory makefiles to makefile.defs in the top level directory of the Praat sources. You can also make a link or shortcut to makefile.defs.mingw32, as long as the name of the link or shortcut is makefile.defs.

cd ~/sources_5242
ln -s makefiles/makefile.defs.mingw32 makefile.defs

Installing MinGW

Installing MinGW on Windows

Follow the direction in http://www.mingw.org/wiki/InstallationHOWTOforMinGW.

After installation you can use MinGW by way of the MinGW Shell which runs the Bash shell.

Installing MinGW on Apple Macintosh

There is some information on MinGW for Mac OSX here. However, it is easier to use the MacPorts system (when it gets the correct GCC version again).

Installation of the MinGW suit with GCC 4.8 (Praat 5.3.78 and higher)

From Praat version 5.3.78 You need MinGW with GCC version 4.7 or higher. This might be a problems on Mac OSX as MacPorts has MinGW with GCC version 3.5 installed. You can find a MinGW installer for the Mac with GCC version 4.8 at Cross GCC:
http://crossgcc.rts-software.org/doku.php?id=compiling_for_win32

To set up the links with the correct names run the following commands:

# create a directory /opt/local/mingw32
sudo mkdir /opt/local/mingw32/
sudo ln -s /usr/local/gcc-4.8.0-qt-4.8.4-for-mingw32/win32-gcc/i586-mingw32/lib /opt/local/mingw32/
sudo ln -s /usr/local/gcc-4.8.0-qt-4.8.4-for-mingw32/win32-gcc/i586-mingw32/include /opt/local/mingw32/
sudo ln -s /opt/local/mingw32 /mingw32

sudo mkdir /opt/local/mingw32/bin
sudo ln -s /usr/local/gcc-4.8.0-qt-4.8.4-for-mingw32/win32-gcc/bin/i586-mingw32-ar /opt/local/mingw32/bin/ar
sudo ln -s /usr/local/gcc-4.8.0-qt-4.8.4-for-mingw32/win32-gcc/bin/i586-mingw32-ranlib /opt/local/mingw32/bin/ranlib
sudo ln -s /usr/local/gcc-4.8.0-qt-4.8.4-for-mingw32/win32-gcc/bin/i586-mingw32-gcc /opt/local/mingw32/bin/gcc
sudo ln -s /usr/local/gcc-4.8.0-qt-4.8.4-for-mingw32/win32-gcc/bin/i586-mingw32-g++ /opt/local/mingw32/bin/g++
sudo ln -s /usr/local/gcc-4.8.0-qt-4.8.4-for-mingw32/win32-gcc/bin/i586-mingw32-windres /opt/local/mingw32/bin/windres

For the time being, you will have to adapt sys/melder.h in the Praat sources. On line 36-39, change:
#ifdef __MINGW32__
#undef swprintf
#define swprintf __mingw_snwprintf
#endif
Into
#ifdef __MINGW32__
#undef swprintf
#define swprintf _snwprintf
#endif

Using MacPorts (Praat versions upto 5.3.77)

Install the MacPorts system following the instructions from http://www.macports.org/install.php. You might find it convenient to also install the MacPortsGUI, or Porticus. However, check whether these are compatible with the MacPorts version you installed. Note that you must have sudo rights to install anything on Mac OSX.

On the Mac, open a terminal window and type:

sudo port install i386-mingw32-gcc i386-mingw32-binutils i386-mingw32-libunicows i386-mingw32-runtime i386-mingw32-w32api
You will be asked for your password. Installation might take some time.

When using MacPorts, MinGW will be installed under /opt/local/i386-mingw32/ with the binaries in /opt/local/bin. However, the Praat makefile assumes that everything is installed under /mingw32. Moreover, the programs have names that differ from those the makefile assumes. And finally, windres seems to be in an unexpected place.

To set up the links with the correct names run the following commands:

# create a directory /opt/local/mingw32
sudo mkdir /opt/local/mingw32/
sudo ln -s /opt/local/i386-mingw32/lib /opt/local/mingw32/
sudo ln -s /opt/local/i386-mingw32/include /opt/local/mingw32/
sudo ln -s /opt/local/mingw32 /mingw32

sudo mkdir /opt/local/mingw32/bin
sudo ln -s /opt/local/bin/i386-mingw32-ranlib /opt/local/mingw32/bin/ranlib
sudo ln -s /opt/local/bin/i386-mingw32-gcc /opt/local/mingw32/bin/gcc
sudo ln -s /opt/local/bin/i386-mingw32-g++ /opt/local/mingw32/bin/g++
sudo ln -s /opt/local/bin/i386-mingw32-windres /opt/local/mingw32/bin/windres

NEW: Installing MinGW on Linux and compiling Praat (Lubuntu)

Wilbert Heeringa supplied a detailed recipe to cross-compile the newest versions of Praat for Windows under Linux.

You can find the PDF here.

You can find the original ODT version here.

Installing MinGW on Linux (Debian)

Using Synaptic or apt-get, install mingw32. On the command line this would be:

sudo apt-get install mingw32 mingw32-binutils mingw32-runtime 
You will be asked for your password.

New version of MinGW (the installation process changes somewhat):

sudo apt-get install mingw-w64

Under Linux, MinGW will be installed under /usr/i586-mingw32msvc with the binaries in /usr/bin. However, the Praat makefile assumes that everything is installed under /mingw32. Moreover, the programs have names that differ from those the makefile assumes. And finally, windres seems to be in an unexpected place.

For the new versions of MinGW, replace i586-mingw32msvc by i686-w64-mingw32 for the 32 bit version and x86_64-w64-mingw32 for the 64 bit version.

To set up the links with the correct names run the following commands:

# create a directory /opt/mingw32
sudo mkdir /opt/mingw32/
sudo ln -s /usr/i586-mingw32msvc/lib /opt/mingw32/
sudo ln -s /usr/i586-mingw32msvc/include /opt/mingw32/
sudo ln -s /opt/mingw32 /mingw32

sudo mkdir /opt/mingw32/bin
sudo ln -s /usr/bin/i586-mingw32msvc-ar /opt/mingw32/bin/ar
sudo ln -s /usr/bin/i586-mingw32msvc-ranlib /opt/mingw32/bin/ranlib
sudo ln -s /usr/bin/i586-mingw32msvc-gcc /opt/mingw32/bin/gcc
sudo ln -s /usr/bin/i586-mingw32msvc-g++ /opt/mingw32/bin/g++
sudo ln -s /usr/bin/i586-mingw32msvc-windres /opt/mingw32/bin/windres

Installing the header files and libraries

After installation of the MinGW suit, the header files required by Praat must be installed. These are the DirectX headers, two header files from the Windows SDK, pthreads-win32 headers, and gdiplus headers and library. It is best to check whether these headers and libraries might already be included in your MinGW suite (e.g., in the Cross GCC suite for the Mac).

Headers should be placed in the relevant include directory, libraries in the lib directory: For Windows and Mac OSX, things work fine without changes.

Linux

To make things interesting, the GdiPlus*.h header files (and some others) are often called with assorted case errors. As only Linux is case sensitive, this will trip up only Linux. As a cludge until the sources and libraries have been corrected, run the following commands.

sudo ln -s /mingw32/include/GdiPlus.h /mingw32/include/gdiplus.h
sudo ln -s /mingw32/include/GdiPlusimageAttributes.h /mingw32/include/GdiPlusImageAttributes.h
sudo ln -s /mingw32/include/GdiPlusMetaFile.h /mingw32/include/GdiPlusMetafile.h
sudo ln -s /mingw32/include/shlobj.h /mingw32/include/Shlobj.h
Then try the following command:
find /usr/i586-mingw32msvc/include/ -iname 'GdiPlus*.h'|perl -ane 'chomp;$o=$_;s/GdiPlus/Gdiplus/g;print "sudo ln -s $o $_\n"'
Now check and double check whether the resulting sudo command lines are correct! If they are correct, append |bash after this line and run it again. If you do not know what these lines are supposed to do, do not try this.

Compiling under MinGW

If you have followed the steps above regarding the makefile.defs.mingw32 file, you can now compile praat. Replace the version number below (_5238) with the version number of the sources you want to compile.

Windows XP

Start MinGW shell from the start menu. Go to the top level directory with the Praat source and enter:

cd ~/sources_5238
make
Go do something else, because it will take some time.

Mac OSX

Open a terminal window. Go to the top level directory with the Praat source and enter:

cd ~/sources_5238
make
Go do something else, because it will take some time.

You can test out the compiled praat.exe on OSX using a WineBottler. Winebottler is based on Wine.

Linux

Open a terminal window. Go to the top level directory with the Praat source and enter:

cd ~/sources_5238
make
Go do something else, because it will take some time.

You can test out the compiled praat.exe on Linux using a Wine.