FAQ C Compile

From LibGD

Contents

HowTo compile libgd and dependent libs from source

Prerequisites

First of all you need an ANSI C compiler.

Unices/Linux compiler

On Unix/Linux platform there's almost always gcc the preferred compiler. In most cases gcc is installed by default - if not then you can install it with your system's package manager.

Win32 compiler

For native Windows there are a number of free compilers available:
the MingW32 gcc compiler
the Bloodshed Dev-C++ (IDE bundled with MingW32)
the OpenWatcom C/C++ compiler
the lcc-win32 compiler system for windows
the Free Borland C++Builder Compiler 5.5
the MS Visual C++ Express
the commercial MSVC compilers are also supported.

NetWare compiler

To compile for the NetWare platform you can use:
the OpenWatcom C/C++ compiler
the native Win32 NLM-Cross gcc compiler
the native Linux NLM-Cross gcc compiler
the native NetWare NLM-Cross gcc compiler (untested yet)
Beside these free compilers the formerly official and commercial MetroWerks CodeWarrior also works.

Download all source packages

The libgd depends on four external libraries if you want to compile it with all possible features.
So start by collecting all the needed libraries and compile them first...
download libgd from http://www.libgd.org/Downloads
download libpng from http://www.libpng.org/pub/png/libpng.html
download zlib from http://www.zlib.net/
download libjpeg from http://www.ijg.org/
download freetype2 from http://sourceforge.net/projects/freetype/
After you have download all libs you should extract them to a common directory level, f.e. lets say we use c:\projects on Win32, or ~/projects on Linux. After you have extracted all, it should look like below (version numbers may differ):

c:\projects\gd-2.0.34
c:\projects\libpng-1.2.16
c:\projects\zlib-1.2.3
c:\projects\jpeg-6b
c:\projects\freetype-2.3.4

or similar for Unices/Linux:

~/projects/gd-2.0.34
~/projects/libpng-1.2.16
~/projects/zlib-1.2.3
~/projects/jpeg-6b
~/projects/freetype-2.3.4

Compile the dependent libraries

Unices/Linux

All dependent libs should have autoconfigure woodoo - so the compile step is in most cases:

./configure
make
make install

Win32

Although for most of these libs there are Win32 binaries available it is not recommended to use them because in most cases you dont know which compiler was used, and using libs build with different compilers will almost allways end up in GFPs on Win32.
The following describes usage of the MSVC6 compiler; if you want to use one of the above mentioned free compilers then you should consider to use CMake. Before we can compile libgd itself we first need all dependent libs; so lets start with these...
Some come with project files, others with commandline makefiles. Lets start with libpng - this comes with a project file:
c:\projects\libpng-1.2.16\projects\visualc6\libpng.dsw
start the MSVC6 IDE and open the project file, then select the build target 'Release' and compile.
The Freetype2 library also comes with a project file:
c:\projects\freetype-2.3.4\builds\win32\visualc\freetype.dsw
open the project file from IDE, then select the build target 'Release' and compile.
Now lets compile those which come with nmake makefiles. For that open a CMD box and first execute VCVARS32.bAT to set all paths correctly. Then change to the directory of zlib and compile with nmake:

cd c:\projects\zlib-1.2.3
nmake -f win32/Makefile.msc

Next is the JPEG library; there we first need to copy the right config file:

cd c:\projects\jpeg-6b
copy jconfig.vc jconfig.h
nmake -f makefile.vc nodebug=1

If all went fine up to here we can build libgd; but first we need to edit the c:\projects\gd-2.0.34\Makefile and fix the paths to the dependent libs:

FREETYPE2=../../freetype-2.3.4
LIBJPEG=../../jpeg-6b
LIBPNG=../../libpng-1.2.16
ZLIB=../../zlib-1.2.3

then the name of freetype2.lib needs to be changed to freetype234.lib; now we can compile libgd:

cd c:\projects\gd-2.0.34\windows
nmake

NetWare

Currently there are no makefiles for NetWare included with libgd; but you can download an archive with the makefiles here:
http://www.gknw.net/test/libgd/gd-2.0.34-build-nw.tar.gz
extract the archive into the libgd source tree, then change to the ./netware directory.
The build uses GNU make and awk; here you can download native Win32 versions:
http://www.gknw.net/development/prgtools/
Set a search path to your compiler and the tools; set the environment var NDKBASE properly, and then type:

make

to compile the commandline test samples use:

make test-cmds
Views
Personal tools

This a PHP.net Project

This library was originally developed by Thomas Boutell