MainDocs:MinGW

From ClanLib Game SDK

Contents

IMPORTANT

ClanLib 2.0 is not supported under MingW. If you have any trouble getting this to work, try searching the forums. And if you make it work, please update this guide!

The following text is the description for using it under ClanLib 1.0:

Using MinGW under Win32

This readme will guide you with installing, compiling ClanLib and creating your first ClanLib application using the MinGW compiler and MSYS toolset on Win32 or a gcc ix86-mingw32msvc cross-compiler (i.e. you can compile ClanLib in Linux and then run the binaries in Windows! (or even run them using a Windows emulator like Wine...)). You should also be able to compile ClanLib with Cygwin, the ./configure script will detect Cygwin and append the '-mno-cygwin -DWIN32' flags to the compiler call.

Requirements

To compile and use ClanLib you need some other libraries. As with any ClanLib target you need to zlib, libjpeg and libpng. There are links from the ClanLib download page (www.clanlib.org/download) to all these libraries.

All libraries should be named as Unix libraries (i.e. libjpeg.a instead of jpeg.lib) and has to be installed so that the compiler can find both the archive files (*.a) and the include files.

You also need the DirectX libraries and headers version 7 or later. Just google the net to find them. It should be possible to use the DirectX SDK from MS but there are also some MinGW specific packages out there. At the moment of writing there is a DirectX 7 MinGW package at:

Other additional libraries for MinGW can be found at (site looks a bit outdated, but might still be helpful):

Instructions on how to build a cross-compile environment can be found at:

If you try to compile the other libraries from source you might want to '--enable-static --disable-shared' at ./configure time since often the DLL build process is a bit buggy and also doesn't lead to having a standalone binary in the end, so static libraries should be preferred.

Compiling ClanLib

Compiling ClanLib works buy using the standard ./configure script as with most other Free Software.

ClanLibs configure script should be able to detect a mingw or cygwin environment automatically and setup everything according to that. As with other libraries, compiling a static library is recomment if you want a binary that doesn't depend on extra .dll's. So to compile you would do:

 ./configure --enable-static --disable-shared
 make
 make install

If you want to cross compile, you have to use the cross-configure.sh scripts as documented on:

or pass the target options manually.


Compiling ClanLib applications

When you compile an application that uses ClanLib you have to use the -mthreads option to enable multithreading.

Depending on which ClanLib modules you use you also may have to link with some extra libraries:

Module Extra linker flags

clanCore -lz clanDisplay -lwinmm -lddraw -ldinput -ldxguid -ljpeg -lpng clanGL -lopengl32 -lglu32 clanSound -ldsound -lwinmm clanNetwork -lws2_32

If you want to try the ClanLib examples in the Examples directory you'll have to adjust the makefiles to include the above mentioned compiler and linker flags. [FIXME: in the future this should be handled automatically by pkg-config, but currently thats not the case]


Simple makefile example

MY_GAME=my_great_game
OBJS=badies.o goodies.o lots_of_weapons.o
 
CXX=g++
 
CXXFLAGS= -mthreads
CLANLIBS= -lclanApp -lclanGL -lclanDisplay -lclanCore
EXTRALIBS= -lz -lwinmm -lddraw -ldinput -ldxguid -ljpeg -lpng \
           -lopengl32 -lglu32
 
PROGRAM: OBJS
	$(CXX) $(CXXFLAGS) -o $(MY_GAME) $(OBJS) $(CLANLIBS) $(EXTRALIBS)

Note that you should minimum link with clanCore, clanDisplay, clanGL and clanApp.

Note that it is important to realize that in order to get your code compiled, some of the libraries should be put in a certain order.

For example: If you want to compile code that is involving GUI stuff, you will need to link your program with clanGUI library. In addition, You might also need to include clanGUIStyleBoring and clanGUIStyleSilver libraries in your makefile. These libraries should go before clanDisplay library, and both the clanGUIStyleBoring and clanGUIStyleSilver libraries should be put before clanGUI.

One possibility of the libraries orders would be:

  -lclanGUIStyleBoring -lclanGUIStyleSilver -lclanGUI -lclanApp -lclanGL 
  -lclanDisplay -lclanCore

If you need to link your program with any other libraries and the compiler complains something about "undefined reference to <some stuff>", and you are sure that the libraries that you link with, already contain the <stuff>, you will probably need to shuffle your libraries order abit.

You may also need to check that the required libraries have already been installed. The basic ClanLib libraries are:

These libraries filenames are usually prefixed by "lib" and followed by ".a", e.g. libclanApp.a