The Allegro Wiki is migrating to github at https://github.com/liballeg/allegro_wiki/wiki

Difference between revisions of "Building with msys2"

From Allegro Wiki
Jump to: navigation, search
m
 
(16 intermediate revisions by 6 users not shown)
Line 8: Line 8:
  
 
MSYS2 archives can be found on sourceforge  
 
MSYS2 archives can be found on sourceforge  
* [http://sourceforge.net/projects/msys2/files/Base/x86_64/ here] for the 64 bits version (x86_64)
+
* [http://sourceforge.net/projects/msys2/files/Base/x86_64/ here] for the 64 bits version (x86_64)
 
   
 
   
* [http://sourceforge.net/projects/msys2/files/Base/i686/ here] for the 32 bits version (i686)
+
* [http://sourceforge.net/projects/msys2/files/Base/i686/ here] for the 32 bits version (i686)
  
 
choose the one matching your Windows system.
 
choose the one matching your Windows system.
 
  
 
== Install ==
 
== Install ==
Line 51: Line 50:
 
== Run msys ==
 
== Run msys ==
  
Tu run MSYS2 you can use any of the <tt>mingwXX_shell.bat</tt> you have in the installeation folder, use the 64 or 32 version depending on the MinGW compiler you will use.
+
Tu run MSYS2 you can use any of the <tt>mingwXX_shell.bat</tt> you have in the installation folder, use the 64 or 32 version depending on the MinGW compiler you will use.
  
 
For the sake of this guide we will assume you're working on a 64-bit system and thus will launch <tt>mingw64_shell.bat</tt>
 
For the sake of this guide we will assume you're working on a 64-bit system and thus will launch <tt>mingw64_shell.bat</tt>
Line 58: Line 57:
  
 
It could also come handy to ''create a shortcut'' to this batch file, and place it on your desktop for easy retrieval.
 
It could also come handy to ''create a shortcut'' to this batch file, and place it on your desktop for easy retrieval.
 
  
 
== Getting the tools to do the job ==
 
== Getting the tools to do the job ==
Line 79: Line 77:
  
 
<source lang="bash">
 
<source lang="bash">
  pacman -S mingw-w64-x86_64-toolchain
+
  pacman -S mingw-w64-x86_64-gcc
 +
pacman -S mingw-w64-x86_64-gdb # ability to debug is always useful
 
</source>
 
</source>
  
 
...will install a fair number of packages that will give you the 64-bit flavor of the latest stable GCC compiler and tools.
 
...will install a fair number of packages that will give you the 64-bit flavor of the latest stable GCC compiler and tools.
  
Then we need [http://git-scm.com/ git] source control management to (later) get the Allegro sources, and the latest [http://www.cmake.org/ cmake] development version to (later) '''compile''' Allegro.
+
Then we need [http://git-scm.com/ git] source control management to (later) get the Allegro sources, and the latest [http://www.cmake.org/ cmake] development version to (later) set up the building stage, and last the ubiquitous [http://www.gnu.org/software/make/ make] to actually '''build''' Allegro.
  
 
<source lang="bash">
 
<source lang="bash">
 
  pacman -S git
 
  pacman -S git
  pacman -S mingw-w64-x86_64-cmake-git
+
pacman -S make                        # this is MSYS2 make, also part of 'base-devel' group                          #
  pacman -S mingw-w64-x86_64-pkgconf    # optional, but could be useful with cmake #
+
  pacman -S mingw-w64-x86_64-cmake      # cmake is fine, earlier versions of this guide recommended cmake-git to automatically find Freetype #
 +
  pacman -S mingw-w64-x86_64-pkg-config  # optional, but could be useful with cmake                                     #
 
</source>
 
</source>
  
 
This should be all you need to get allegro to compile, next are the dependencies.
 
This should be all you need to get allegro to compile, next are the dependencies.
 
  
 
== Install dependencies ==
 
== Install dependencies ==
Line 100: Line 99:
  
 
<source lang="bash">
 
<source lang="bash">
pacman -S mingw-w64-x86_64-freetype  # required for truetype fonts loading                                               #
+
pacman -S mingw-w64-x86_64-freetype  # required for truetype font loading
pacman -S mingw-w64-x86_64-physfs    # also installs zlib and bzip2 - required for Loading files from compressed archives #
+
pacman -S mingw-w64-x86_64-physfs    # also installs zlib and bzip2 - required for Loading files from compressed archives
pacman -S mingw-w64-x86_64-libvorbis  # also installs libOGG, required for OGG Audio playback                             #
+
pacman -S mingw-w64-x86_64-libvorbis  # also installs libOGG, required for OGG Audio playback
pacman -S mingw-w64-x86_64-flac      # required for FLAC audio playback                                                   #
+
pacman -S mingw-w64-x86_64-flac      # required for FLAC audio playback
pacman -S mingw-w64-x86_64-dumb      # required for audio tracker files (e.g. .mod, .it etc)                             #
+
pacman -S mingw-w64-x86_64-dumb      # required for audio tracker files (e.g. .mod, .it etc)
pacman -S mingw-w64-x86_64-theora    # required for Video Playback - ALLEGRO 5.1 only                                     #
+
pacman -S mingw-w64-x86_64-libtheora  # required for Video Playback - ALLEGRO 5.1 only      
 +
pacman -S mingw-w64-x86_64-libjpeg-turbo
 
</source>
 
</source>
  
 
These are all the dependencies needed to have a full working Allegro 5.1 library built on Windows
 
These are all the dependencies needed to have a full working Allegro 5.1 library built on Windows
 
  
 
== Download Allegro Sources from git repository ==
 
== Download Allegro Sources from git repository ==
Line 116: Line 115:
  
 
<source lang="bash">
 
<source lang="bash">
git clone git://git.code.sf.net/p/alleg/allegro
+
git clone https://github.com/liballeg/allegro5.git
 
</source>
 
</source>
  
 
This will create a folder called ''allegro'' with the Allegro Source inside.
 
This will create a folder called ''allegro'' with the Allegro Source inside.
 
  
 
== Build ==
 
== Build ==
Line 131: Line 129:
  
 
<source lang="bash">
 
<source lang="bash">
  # inside 'allegro' folder #
+
  # outside of the 'allegro' folder #
  mkdir build-Allegro-static-monolith
+
  mkdir build_allegro_monolith
  cd build-allegro-static-monolith
+
  cd build_allegro_monolith
 
  cmake \
 
  cmake \
 
-G"MSYS Makefiles" \
 
-G"MSYS Makefiles" \
-DCMAKE_SYSTEM_PREFIX_PATH:PATH=/mingw64/x86_64-w64-mingw32/ \
+
-DCMAKE_INSTALL_PREFIX=/mingw64/x86_64-w64-mingw32 \
 
-DWANT_MONOLITH=on \
 
-DWANT_MONOLITH=on \
-DSHARED=off \
+
..
../allegro
 
 
</source>
 
</source>
  
The previous cmake command set the build for the '''static monolith''' version of the library along with all Allegro '''examples''' and '''demos'''
+
The previous cmake command set the build for the '''monolith''' version of the library along with all Allegro '''examples''' and '''demos'''
 +
 
 +
If you receive errors relating to CMake such as <tt>Could NOT find DINPUT (missing:  DINPUT_INCLUDE_DIR)</tt> it's likely CMake isn't resolving the directx headers and libraries. These are included in msys.
 +
 
 +
Try passing an altered PATH variable by replacing <tt>cmake</tt> with <tt>PATH=/mingw64/x86_64-w64-mingw32:$PATH cmake</tt> or <tt>PATH=/mingw32/i686-w64-mingw32:$PATH cmake</tt> in the above install line.
  
 
2. Then you issue the <tt>make</tt> command to actually '''build''' the sources, and then install them in the default location (should be '<tt>'''/mingw64'''</tt>' in the MSYS2 environment).
 
2. Then you issue the <tt>make</tt> command to actually '''build''' the sources, and then install them in the default location (should be '<tt>'''/mingw64'''</tt>' in the MSYS2 environment).
  
 
<source lang="bash">
 
<source lang="bash">
  # inside 'allegro\build-Allegro-static-monolith' folder #
+
  # inside the 'build_allegro_monolith' folder #
 
  make && make install
 
  make && make install
 
</source>
 
</source>
  
Now you should have the headers as well as the static monolith library installed within you compiler standard search path.
+
Now you should have the headers as well as the monolith library installed within you compiler standard search path.
  
This means '<tt>'''#include'''</tt>' statements will be automatically resolved by the preprocessor and that you have to pass the '<tt>-lallegro_monolith-static</tt>' flag to the linker to build any Allegro application.
+
This means '<tt>'''#include'''</tt>' statements will be automatically resolved by the preprocessor and that you have to pass the '<tt>-lallegro_monolith</tt>' flag to the linker to build any Allegro application.
  
  
 
You're now ready to use Allegro5, have fun with it and feel free to drop by [https://www.allegro.cc/forums/index Allegro.cc forums] if you need any help.
 
You're now ready to use Allegro5, have fun with it and feel free to drop by [https://www.allegro.cc/forums/index Allegro.cc forums] if you need any help.

Latest revision as of 21:59, December 11, 2016

Introduction

The following guide explains how to set up MSYS2 minimal system on Windows and use the already available MinGW compiled dependencies to build Allegro 5 from source from the command line.

Required Downloads

You will need to download the MSYS2[1] package and this has to be unzipped in a directory of choice, to do this you can use for example the excellent 7-zip

MSYS2 archives can be found on sourceforge

  • here for the 64 bits version (x86_64)
  • here for the 32 bits version (i686)

choose the one matching your Windows system.

Install

Download the most recent msys2-base-XXXXXXXX.tar.xz archive in the location provided in the previous chapter, unpack it and put it somewhere you're comfortable with.

  • Note: it is always a good measure to select a PATH with no spaces in it to avoid the most common problems.


Let's say in this example you put it in C:\msys, ending up with it installed in C:\msys\msys64 root directory.

It should look something like this inside:

07/05/2014  13:09    <DIR>          .
07/05/2014  13:09    <DIR>          ..
28/02/2014  16:49               167 autorebase.bat
09/05/2014  23:32    <DIR>          bin
04/04/2014  22:35    <DIR>          dev
06/05/2014  21:59    <DIR>          etc
04/04/2014  22:35    <DIR>          home
06/05/2014  21:59    <DIR>          include
06/05/2014  21:59    <DIR>          lib
02/02/2014  20:57             1.099 mingw32_shell.bat
02/05/2014  22:57    <DIR>          mingw64
02/02/2014  20:57             1.099 mingw64_shell.bat
02/02/2014  20:57            37.758 msys.ico
02/02/2014  20:57             1.096 msys2_shell.bat
06/05/2014  21:59    <DIR>          sbin
06/05/2014  21:59    <DIR>          share
06/05/2014  21:48    <DIR>          ssl
10/05/2014  22:41    <DIR>          tmp
04/04/2014  22:29    <DIR>          var


Run msys

Tu run MSYS2 you can use any of the mingwXX_shell.bat you have in the installation folder, use the 64 or 32 version depending on the MinGW compiler you will use.

For the sake of this guide we will assume you're working on a 64-bit system and thus will launch mingw64_shell.bat

  • Note: usually the first time you run MSYS2 shell you'll be asked to exit immediately, do so either closing the window or by tiping exit on the MSYS2 prompt.

It could also come handy to create a shortcut to this batch file, and place it on your desktop for easy retrieval.

Getting the tools to do the job

First of all a word of premise, MSYS2 uses a port of Arch Linux's pacman[2] to manage packages for the distribution.

This is indeed a very powerful and convenient way to get all the tools (compiler, make, cmake, dependiecies) you need to get allegro compiled from source.

First of all you need to sync the database with the latest repository, on the command line type:

 pacman -Sy

and the program should update (if need there should be) the local databse to the three online repositories (msys2, mingw64 and mingw32)

  • IMPORTANT NOTE: if you intend to use the 32-bit version of MinGW-gcc, you need to susbstitute EACH occurrence of 'x86_64' in the following instructions with 'i686'

Then, we need our compiler, binutils and all the stuff that come with gcc...

 pacman -S mingw-w64-x86_64-gcc
 pacman -S mingw-w64-x86_64-gdb # ability to debug is always useful

...will install a fair number of packages that will give you the 64-bit flavor of the latest stable GCC compiler and tools.

Then we need git source control management to (later) get the Allegro sources, and the latest cmake development version to (later) set up the building stage, and last the ubiquitous make to actually build Allegro.

 pacman -S git
 pacman -S make                         # this is MSYS2 make, also part of 'base-devel' group                           #
 pacman -S mingw-w64-x86_64-cmake       # cmake is fine, earlier versions of this guide recommended cmake-git to automatically find Freetype #
 pacman -S mingw-w64-x86_64-pkg-config  # optional, but could be useful with cmake                                      #

This should be all you need to get allegro to compile, next are the dependencies.

Install dependencies

Inside the shell, type these commands:

pacman -S mingw-w64-x86_64-freetype   # required for truetype font loading
pacman -S mingw-w64-x86_64-physfs     # also installs zlib and bzip2 - required for Loading files from compressed archives
pacman -S mingw-w64-x86_64-libvorbis  # also installs libOGG, required for OGG Audio playback
pacman -S mingw-w64-x86_64-flac       # required for FLAC audio playback
pacman -S mingw-w64-x86_64-dumb       # required for audio tracker files (e.g. .mod, .it etc)
pacman -S mingw-w64-x86_64-libtheora  # required for Video Playback - ALLEGRO 5.1 only       
pacman -S mingw-w64-x86_64-libjpeg-turbo

These are all the dependencies needed to have a full working Allegro 5.1 library built on Windows

Download Allegro Sources from git repository

Type the following command to retrieve the master branch of Allegro Sources

git clone https://github.com/liballeg/allegro5.git

This will create a folder called allegro with the Allegro Source inside.

Build

Allegro build is a two steps procedure:

1. First you need to issue a cmake command to have the build system set up the necessary makefiles; usually cmake is used with out of source build, meaning you create a specific folder to build into.

Like so:

 # outside of the 'allegro' folder #
 mkdir build_allegro_monolith
 cd build_allegro_monolith
 cmake \
	-G"MSYS Makefiles" \
	-DCMAKE_INSTALL_PREFIX=/mingw64/x86_64-w64-mingw32 \
	-DWANT_MONOLITH=on \
	..

The previous cmake command set the build for the monolith version of the library along with all Allegro examples and demos

If you receive errors relating to CMake such as Could NOT find DINPUT (missing: DINPUT_INCLUDE_DIR) it's likely CMake isn't resolving the directx headers and libraries. These are included in msys.

Try passing an altered PATH variable by replacing cmake with PATH=/mingw64/x86_64-w64-mingw32:$PATH cmake or PATH=/mingw32/i686-w64-mingw32:$PATH cmake in the above install line.

2. Then you issue the make command to actually build the sources, and then install them in the default location (should be '/mingw64' in the MSYS2 environment).

 # inside the 'build_allegro_monolith' folder #
 make && make install

Now you should have the headers as well as the monolith library installed within you compiler standard search path.

This means '#include' statements will be automatically resolved by the preprocessor and that you have to pass the '-lallegro_monolith' flag to the linker to build any Allegro application.


You're now ready to use Allegro5, have fun with it and feel free to drop by Allegro.cc forums if you need any help.