How to build Ghostscript from source code

Table of contents

For other information, see the Ghostscript overview and the instructions on how to install Ghostscript.

General overview

This document describes how to build a Ghostscript executable from source code. There are four major steps to building Ghostscript:

  1. Acquire the compressed archive files of source code for Ghostscript and the required third-party libraries.
  2. Unpack the archive files into the Ghostscript directory and correctly named subdirectories.
  3. Prepare the makefiles, including specific changes for your operating environment and your choice of configuration options.
  4. Invoke "make" to build the software.

The remainder of this document describes each of these steps in detail. Note that some of this process is platform-dependent. After building Ghostscript you must then install it; for that, see the installation instructions.

How to acquire the source code

Building Ghostscript requires the Ghostscript source code itself, and also the source code for some third-party libraries that Ghostscript uses.

Ghostscript source code

Ghostscript is available from all the standard GNU mirrors, e.g.

Ghostscript source code is packaged in two different formats: gzip-compressed tar files (*.tar.gz) and zip files (*.zip). For all versions there are gzip-compressed tar files:


For recent versions of Ghostscript there may also be zip files

("#.##" and "###" are version numbers in punctuated and unpunctuated form.) Software to decompress and extract both formats is available for almost every platform for which Ghostscript is available -- including Unix, DOS, MS Windows, and VMS -- so you can choose the format most convenient for you; but it's up to you to locate that software. See the section on unpacking the source code.

Third-party library source code

To build Ghostscript you need the source code for the Independent JPEG Group (IJG) library, the Portable Network Graphics (PNG) library, and the zlib compression and decompression library. Here are authoritative distribution points for these libraries, where as elsewhere, "#" is used for version numbers. The JPEG source code is quite stable, so the reference here includes the latest version number. The zlib references are version-independent and should always provide the latest version.

Third-party libraries: authoritative sources
zlib (latest)

On DOS or MS Windows one ordinarily uses the zip file kits, in other environments the compressed tar files, but this is simply a matter of convenience, since for the same version of the software the compressed tar file has the same contents as the zip file. Note that each of these libraries has its own version number that has nothing to do with Ghostscript's version number; you should get the highest numbered version. (If you encounter difficulties in the build process you might have to use a lower-numbered version, but don't worry about this yet.) If you're running GNU/Linux, you might check whether these libraries are already available in source form on your system, since many GNU/Linux distributors include them; but we advise you to get the highest version from the Net if you can.

Although the zip archives of an old version of the PNG library may not be named, we refer to it as

On MacOS, the .sit source archive includes the appropriate source versions of these libraries, so no additional downloads are necessary.

How to unpack the source code

Unfortunately there are no generally accepted standards for how to package source code into archives, so the instructions for unpacking Ghostscript are longer than they should be. We begin with a brief explanation of how to extract the two kinds of archive files.

How to unpack compressed tar files generally

Tar (.tar) files are the de facto standard for archiving files on Unix (every Unix system has the tar program), and programs to extract their contents are also widely available for DOS, MS Windows, and VMS. To economize on space and downloading time, Ghostscript's tar files are compressed with GNU gzip, which adds the suffix ".gz" to the file name, giving ".tar.gz".

To unpack a compressed tar file MyArchive.tar.gz you must both decompress it and extract the contents. You can do this in two steps, one to decompress the file and another to unpack it:

gzip -d MyArchive.tar.gz
tar -xf MyArchive.tar

or in a pipeline:

gzip -d -c MyArchive.tar.gz | tar -xf -

or, if you have a program like GNU tar that can handle compressed tar files, with a single command:

tar -zxf MyArchive.tar.gz

The tar program automatically preserves directory structure in extracting files. The Ghostscript source archive puts all files under a directory gs#.##, so using tar to unpack a compressed archive should always properly create that directory, which we will call the "gs directory". Make sure you're positioned in the parent of the gs directory before unpacking the files. If a subdirectory doesn't already exist, tar creates it.

Some other programs -- under MS Windows, for instance -- can also unpack compressed tar files, but they may not automatically preserve directory structure nor even extract files into the current directory. If you use one of these, you must

How to unpack zip files generally

Zip files are the de facto standard for archiving files on DOS and MS Windows, and programs to extract their contents are widely available for DOS, MS Windows, Unix, VMS, and other platforms. Zip files are at once an archive format and a compressed format, so an unzipping program decompresses and extracts archived files as a single step.

One common 16-bit DOS program is pkunzip, which comes in the pkzip package. If you use this, you should ensure that you have at least version 2.04g, because with its -d switch, that version of pkunzip preserves the directory structure of archived files when extracting them; see below. Another popular free program to unpack zip archives, available for DOS and MS Windows (16-bit and 32-bit), Unix, VMS, and other platforms, is InfoZIP unzip:

Unlike pkunzip, InfoZIP unzip automatically preserves the directory structure of extracted files. So if you have a zip archive

Extracting zipped files
Command      Preserves directory structure

pkunzip   Does NOT
pkunzip -d   DOES (note the -d switch)
unzip   DOES

As with the compressed tar files, make sure you're positioned in the parent of the gs directory before unpacking the files. If a subdirectory doesn't already exist, zip or pkunzip -d creates it.

How to unpack Ghostscript itself

At this point you have acquired all the source code and are ready to unpack it according to the preceding guidelines for tar files or zip files. To unpack the Ghostscript source, make the parent of the (new) gs directory the current directory.

2-step:     gzip -d ghostscript-#.##.tar.gz
tar -xf ghostscript-#.##.tar
Pipe:   gzip -d -c ghostscript-#.##.tar.gz | tar -xf -
GNU tar:   tar -zxf ghostscript-#.##.tar.gz
pkunzip:   pkunzip -d
pkunzip -d
unzip:   unzip

All the Ghostscript source files are now in subdirectories of the gs directory.

Source subdirectories
Subdirectory      Contents

src/   C source code and makefiles
lib/   PostScript files and scripts used when running Ghostscript
doc/   Documentation
man/   Unix man pages
examples/   Sample PostScript files

How to unpack the third-party libraries

The Ghostscript makefiles expect to find the JPEG, PNG, and zlib source code in specific subdirectories of the gs directory, and this means you must pay careful attention to unpacking the source code for these packages. Use the same method for all of them, no matter how they're packaged:

  1. Make the gs directory current.
  2. Unpack the archive file, creating a subdirectory (which will include a version number).
  3. Whatever the subdirectory's original name, rename it to the versionless name shown just below.

If you're uncertain how to unpack an archive, review the sections on compressed tar files and zip files.

3d-party software subdirectories
Package      Possible
original name
     Rename to

JPEG   ./jpeg-6b   ./jpeg
PNG   ./libpng-#.##   ./libpng
zlib   ./zlib-#.#.#   ./zlib

How to prepare the makefiles

The Ghostscript makefiles are very large and complex in order to deal with the diverse requirements of all the different systems where they may be used.

New with this release is support for the GNU autoconf tool for generating an automatic configuration script. If you're on unix or a related system that supports unix shell scripts, this is the easiest option to use. Simply type:

from the top level of the ghostscript source directory. It should configure itself based on what's available on your system, warn you of any missing dependencies, and generate a Makefile. At this point you can skip to the section invoking make below. Note that the autoconfiguration option is only available with the unix .tar distribution of the source.

If your system doesn't support the configure script or you don't wish to use it, you can use the traditional ghostscript makefile system, editing the options by hand to match your system as described below. Fortunately, the only makefiles you're likely to want to change are relatively small ones containing platform-specific information.

Platform-specific makefiles
Makefile      Used for

bcwin32.mak   MS Windows with Borland/Inprise compilers
msvc32.mak   MS Windows with Microsoft Visual C++ version 4 to 7.
openvms.mak   OpenVMS
os2.mak   OS/2 with the gcc/emx compiler
unix-gcc.mak   Unix with gcc
unixansi.mak   Unix with ANSI C compilers other than gcc
watc.mak   DOS with Watcom compilers
watcw32.mak   MS Windows with Watcom compilers

Platform-independent makefiles
contrib.mak   Contributed device drivers
devs.mak   Maintained device drivers
gs.mak   Documentation and miscellany
int.mak   Main makefile for the PostScript & PDF interpreter
jpeg.mak   JPEG library
lib.mak   Graphics engine
libpng.mak   PNG library
version.mak   Version and release date
zlib.mak   zlib library

Since these files change from one Ghostscript version to another, sometimes substantially, and since they all include documentation for the various options, here we don't duplicate most of that documentation: we recommend strongly that you review the entire makefile specific for your operating system and compiler before building Ghostscript.

Changes for your environment

You must edit the platform-specific makefile to change any of these:

The platform-specific makefiles include comments describing all these except the DEVICE_DEVS options. These are described in devs.mak and contrib.mak, even though the file that must be edited to select them is the platform-specific makefile.

Some platform-specific options are described in the sections for individual platforms. See the "Options" section near the beginning of the relevant makefile for more information.

Selecting features and devices

You may build Ghostscript with any of a variety of features and with any subset of the available device drivers. The complete list of features is in a comment at the beginning of gs.mak, and the complete list of drivers in comments at the beginning of devs.mak and contrib.mak. To find what devices a platform-specific makefile selects to include in the executable, look in it for all lines of the form

FEATURE_DEVS={list of features}
DEVICE_DEVS*={list of devices}

For example, if the makefile has


indicating that only the PostScript Level 2 facilities should be included, you might make it


to add the ability to interpret PDF files. (In fact, FEATURE_DEVS in the current Unix makefiles already includes $(PSD) The Unix makefile also defines


indicating that the X Windows driver should be included, but since platform-specific makefiles as distributed normally include many of the possible features and drivers, you will probably rather remove from the makefile the features and drivers you don't want. It does no harm to include unneeded features and devices, but the resulting executable will be larger than needed.

You may edit the FEATURE_DEVS line to select or omit any of the features listed near the beginning of gs.mak, and the DEVICE_DEVS* lines to select or omit any of the device drivers listed near the beginning of devs.mak and contrib.mak. The first device listed in the definition of DEVICE_DEVS becomes the default device for this executable; see the usage documentation for how to select an output device at run time using the -sDEVICE= switch. If you can't fit all the devices on a single line, you may add lines defining

DEVICE_DEVS1=$(DD){dev11}.dev ... $(DD){dev1n}.dev
DEVICE_DEVS2=$(DD){dev21}.dev ... $(DD){dev2n}.dev

etc., up to DEVICE_DEVS15. Don't use continuation lines -- on some platforms they don't work.

Note that if you want to include a driver named xxx, you must put $(DD) in DEVICE_DEVS*. Similarly, if you want to include a feature related to the PostScript or PDF language interpreters (PostScript level 1 .. 3, or other language features such as the ability to read EPSF files or TrueType font files), you must represent it as $(PSD) If you are linking only the graphics library -- not the language interpreter(s) -- with an application and want to include optional graphics library features such as CIE color, you represent them as $(GLD)

Precompiled run-time data

Ghostscript normally reads a number of external data files at run time: initialization files containing PostScript code, fonts, and other resources such as halftones. By changing options in the top-level makefile for the platform, you can cause some of these files to be compiled into the executable: this simplifies installation, improves security, may reduce memory requirements, and may be essential if you are planning on putting Ghostscript into ROM.

To compile the initialization files (lib/, etc.) into the executable, change the 0 to a 1 in the line


To compile fonts into the executable, see Precompiling fonts.

To compile threshold-array halftones into the executable, see the "Compiled halftone" section of int.mak for a sample makefile fragment, genht.c for the syntax of halftone data files, and lib/ for a sample data file. Note that even though the data files use PostScript syntax, compiled halftones do not require the PostScript interpreter and may be used with the graphics library alone.

GNU readline

GNU Ghostscript distributions include support for GNU readline, but this is not officially supported at this time. We will, however, welcome bug fixes or updates, and distribute them with subsequent releases.

Setting up "makefile"

After going through the steps just described to unpack the sources, make any desired changes to the makefiles, and unpack or create links to the third party libraries, as the final step in preparing to build Ghostscript you must usually associate the name "makefile" with the correct makefile for your environment so the make command can find it. See the section on your particular platform for how to do that if necessary.

Invoking "make"

Builds Ghostscript without debugging options.
make debug
Builds Ghostscript with debugging options and additional internal error checks. The program will be somewhat larger and slower, but it will behave no differently unless you actually turn on debugging options at execution time with the -DDEBUG or -Z command line switches described in the usage documentation.
make pg
On Unix platforms, builds with the -pg compiler switch, creating an executable for time profiling.
make begin
On PC platforms, attempts a quick and dirty compilation of all the .c files in the current directory. See the more detailed explanation.
make install
After building, installs the Ghostscript executables, support files, and documentation, but does not install fonts. See the installation documentation.
make clean
Deletes all the files created by the build process (relocatables, executables, and miscellaneous temporary files). If you've built an executable and want to save it, move it first to another place, because "make clean" deletes it.

Note: on most platforms some of these simple instructions don't quite work in one way or another. Read the section on your specific platform.


If you are compiling Ghostscript on machines X1 ... Xn with cross-compilers that generate code for machine Y, you must first perform several extra steps on some machine Z (not necessarily of the same type as either Xi or Y). First of all, choose a makefile appropriate for Z and edit it to reflect the run-time options you wish to include (FEATURE_DEVS, DEVICE_DEVS*, and any other relevant options), just as for non-cross-compilation.

If Z runs Unix, perform the following steps:

  1. On Z,
    make clean
    make obj/arch.h obj/genconf obj/echogs
  2. Edit obj/arch.h to reflect the architecture of Y.
  3. On Z,
    make CC=: CCLD=:
  4. Copy the files obj/*.h from Z to the directory on each Xi that will be used for compilation.
  5. Extract from the file obj/ (on Z) the list of .o files that will be linked: this gives the list of source files that must be compiled.
  6. Do the compilations on Xi.

If Z runs some version of Microsoft Windows with Microsoft Visual C++, use the following steps. NOTE: We have not actually tested this.

  1. On Z,
    nmake clean
    nmake obj\arch.h obj\genconf.exe obj\echogs.exe
  2. Edit obj\arch.h to reflect the architecture of Y.
  3. On Z,
    nmake CC=rem LINK=rem
  4. Copy the files obj\*.h from Z to the directory on each Xi that will be used for compilation.
  5. Extract from the file obj\ (on Z) the list of .obj files that will be linked: this gives the list of source files that must be compiled.
  6. Do the compilations on Xi.

How to build Ghostscript from source (PC version)

All Ghostscript builds in PC (DOS and MS Windows) environments are 32- or 64-bit: 16-bit builds are not supported. The relevant makefiles are

PC makefiles
Makefile    Construction tools    For environment

bcwin32.mak   Borland/Inprise C++ 4.x   32-bit MS Windows 3.1 + Win32s, 95, 98, NT
msvc32.mak   Microsoft Visual C++ 4 to 7   MS Windows 32-bit
watc.mak   Watcom C/386 or C++   MS-DOS 32-bit (extended)
watcw32.mak   Watcom C/386 or C++   MS Windows 32-bit
unix-gcc.mak   Cygnus gcc   Cygnus gnu-win32

To build Ghostscript you need MS-DOS version 3.3 or later and Borland/Inprise C/C++ (4.0 or later); Microsoft Visual C++ (version 4.0 or later); Watcom C/386 (version 8.5 or later) or C++ (any version); or the free djgpp + go32 development system. The options in the makefiles are chosen to strike a balance between RAM consumption and likely usefulness. If you run make in directory {dir}, the default configuration generates an executable that assumes the Ghostscript initialization and font files are in directory {dir}\lib.

Note that the make program supplied with each PC compiler has a different name. We refer to this program generically as make everywhere else in this document, but you will find the correct name for each compiler in the relevant section below that discusses that compiler.

You must have COMMAND.COM in your path to build Ghostscript. After making the changes needed to choose features and devices to build into the executable, you must create the directory where the compiler will do its work (normally the obj subdirectory of the current directory) and the directory where the compiled code will be placed (normally the bin subdirectory). Then to build the Ghostscript executable all you need do is give the make command.

A special make target "begin" attempts to compile all the .c files in the current directory. Some of these compilations will fail, but the ones that succeed will go considerably faster because they don't individually pay the overhead of starting up the compiler. So a good strategy for building the executable for the first time, or after changing a widely used .h file, is to do the fast compilation of everything possible, then the controlled compilation of everything that failed in the first step:

make begin

Note: if you unpack the Ghostscript sources on a DOS or MS Windows system from a Unix tar file, the unpacked files have linefeed alone as the line terminator (the Unix convention) instead of carriage return + linefeed (the Microsoft convention), which may make the C compiler unhappy. One simple way to fix this, if you have the InfoZIP zip and unzip programs, is

zip -l *.bat *.c *.h *.def *.rc      (Letter "l", not the digit "1")
unzip -o   (Rewrite all the same files correctly)
del   (Delete the temporary zip file)

Borland/Inprise environment

To compile Ghostscript with the Borland/Inprise environment (hereafter referred to as just "Borland"), you need Borland C++ (version 4.0 or later); specifically the compiler, make utility, and linker. You also need either the Borland assembler (version 1.0 or later) or the Microsoft assembler (version 4.0 or later).

To create "makefile", give the command

echo !include "src\bcwin32.mak" >makefile

To run the make program, give the commmand


Besides the source files and the makefiles, you need:

*.bat   (a variety of batch files used in the build process)

Comments in the makefiles describe the configuration parameters. If your configuration is different from the following, you should definitely read those comments and see if you want or need to change any of this:


Microsoft Environment

NOTE: We have received reports that the Microsoft Visual C++ 5.0 and 6.0 compilers produce incorrect code for Ghostscript version 6.0 and later, from the same source code that compiles and runs correctly with other compilers. In spite of these reports, several members of the Artifex staff use version 6.0 of the MSVC compiler on a regular basis and we have not found any problems. You may also want to try out the Intel C/C++ compiler, which can be integrated into the Microsoft Visual C++ environment.

To compile Ghostscript using the Microsoft environment, you need Microsoft Visual C++ 4.0 or later with its associated "nmake" utility and linker.

Using Microsoft Developer Studio

Microsoft Developer Studio is the Microsoft Visual C++ integrated development environment. To use it to build Ghostscript: it is first necessary to create a new workspace/project. To create the workspace/project, open Microsoft Developer Studio and select File/New. In the dialog window that is opened, select 'Makefile' as the type of project. Specify a name for the project. (Microsoft does not allow special characters such as ., *, ?, /, or \ as part of project names.) Also specify the location of the master directory for your Ghostscript files. Then select OK.

In the next dialog window, specify the build command line as nmake /f src/msvc32.mak DEVSTUDIO= Note the value for DEVSTUDIO is empty. Then select Finish.

At this point, it is now possible to build Ghostscript using Developer Studio. To build, press F7 or select the build icon. Note: multiple warnings will also given about things like double to float data conversions. Ignore them. We have not found a way to create a single set of sources that does not create warnings with the different compilers and operating systems supported by Ghostscript. We are working to reduce the number of the warning messages.

To run Ghostscript inside of Developer Studio, it is necessary to specify the name of the executable program . Select Project/Settings. Select the Debug tab. Then for Executable for debug session: specify bin/gswin32.exe

To use all of the features of Microsoft Developer Studio for debugging, and modifying Ghostscriptt, you need to finish the remaining steps.

To add the Ghostscript DLL to the project, select Project/Settings. Select the Debug tab. Change the Category to Additional DLLs. Then specify bin/gsdll32.dll.

To specify the Ghostscript program arguments, select Project/Settings. Select the Debug tab. Change the Category to General. Then specify the desired program arguments. For example, specifying: examples/ will result in the tiger example file being displayed when Ghostscript is executed. .

A final note: it is possible to create a command file (build.bat) to be used for the build command line. If many different workspaces/projects are created, it is simpler to use a build batch command file rather than retyping the build command line for each new project. Here is an example used by one of Artifex's staff members. This file is one line:

nmake -f src/msvc32.mak DEVSTUDIO= DEBUG=1 GS_LIB_DEFAULT="./lib/;./font;$(GSROOTDIR)/lib;$(AROOTDIR)/fonts"

The DEBUG=1 enables many debugging features built into Ghostscript. Please note the double quotes around the value for GS_LIB_DEFAULT and the addition of ./lib;./fonts; to its definition. This uses the local (within the project) copy of the lib and fonts directories. This is convenient if any changes need to be made in these directories.

Using the command line

Ghostscript can be made using either the DOS shell or one one of the various command line shells made for Windows.

In order for the makefiles to work properly, two items may have to be changed. If you are not using version 6.x then before building, in src\msvc32.mak find the line "MSVC_VERSION=6" and change it to "MSVC_VERSION=4", "MSVC_VERSION=5" or "MSVC_VERSION=7".

In some cases the location of the Microsoft Developer Studio, needs to be changed. The location of Microsoft Developer Studio is defined by the value of DEVSTUDIO. There are four different definitions of DEVSTUDIO in src\msvc32.mak. There is one for each of the currently supported versions of Microsoft Visual C++ (4, 5, 6 and 7).

The normal installation process for Microsoft Visual C++ includes setting the location of the Microsoft Visual C++ executables (cl.exe, link.exe, nmake.exe, rc.exe) in your PATH definition and the LIB and INCLUDE environment variables are set to point to the Microsoft Visual C++ directories. If this is true then the value for DEVSTUDIO can be changed to empty. I.e. DEVSTUDIO=

If PATH, LIB, and INCLUDE are not correctly set then the value for DEVSTUDIO needs to be defined. For example, for version 6.0, the default definition for the location for the Microsoft Developer Studio is: DEVSTUDIO=C:\Program Files\Microsoft Visual Studio If the path to Microsoft Developer Studio on your system differs from the default then change the appropriate definition of DEVSTUDIO. (Remember that there is a separate definition of DEVSTUDIO for each version of MSVC, so be sure to change the correct definition.)

To run the make program, give the command

nmake -f src\msvc32.mak

Rather than changing src/msvc32.mak, these values can be specified on the make command line, I.e.

nmake -f src\msvc32.mak MSVC_VERSION=6 DEVSTUDIO="C:\Program Files\Microsoft Visual Studio"
nmake -f src\msvc32.mak MSVC_VERSION=7 DEVSTUDIO="C:\Program Files\Microsoft Visual Studio .NET"

Note that double quotes have been added around the path for DEVSTUDIO due to the spaces in the path value.

This command line can also be put into a batch file.

You may get warning messages during compilation about /QI0f being an undefined switch, or the message "dwmain32.def: EXETYPE not supported for platform; ignored" during linking. Multiple warnings will also given about things like double to float data conversions. Ignore them. We have not found a way to create a single set of sources that does not create warnings with the different compilers and operating systems supported by Ghostscript.

The Microsoft VC++ 5.0 compiler locks up when compiling gxi12bit.c with /O2. Compile this file without /O2.

The Microsoft VC++ 5.0 compiler produces a non-working executable if compiling without stack checking. Don't change the setting TDEBUG=1 in msvc32.mak.

Making self-extracting executables

You can build self-extracting Windows executables of Ghostscript. (This is not needed to use Ghostscript.) Currently this requires both the Borland/Inprise and the Microsoft compilers, and also two pieces of third-party software:

You will have to edit src/winint.mak to define WINZIPSE_XE and ZIP_XE respectively as the path names of these programs. See Release.htm for the detailed procedure.

Watcom environment

Because of limitations in the way that Watcom implemented their wmake program, you must run the Watcom tools under MS Windows, even if you are generating a DOS executable. This is very unfortunate, and there is no good technical reason for it, but we were unable to persuade Watcom (now Powersoft) to do anything about it.

To use the Watcom compiler, add to AUTOEXEC.BAT the line "set DOS4G=quiet". Check that AUTOEXEC.BAT also contains a line of the form "set WATCOM={wcdir}" where {wcdir} is the directory where you installed the Watcom tools, and that the setting of PATH includes {wcdir}\binnt (or %WATCOM%\binnt) before {wcdir}\binw (or %WATCOM%\binw). Then to create "makefile":

For     Give the command

DOS   echo !include src\watc.mak >makefile
MS Windows   echo !include src\watcw32.mak >makefile

Before compiling, change the definition of the WCVERSION macro in the makefile (watc.mak or watcw32.mak) to the version of the Watcom compiler you are using. This is necessary to handle some minor incompatibilities between versions.

To run the make program, give the commmand

wmake -u

For information on using the GNU make program with the Watcom compiler to build MS-DOS executables, which avoids the limitations in wmake, see here.

Cygwin32 gcc

A user reports that it is possible to compile Ghostscript for MS Windows NT using the Cygwin32 gcc compiler, GNU make, and the unix-gcc.mak makefile, with only two small source code changes:

Information about this compiler and environment is at the Cygnus site:

Please note that Cygnus's licensing terms aren't quite as liberal about redistribution as either the GNU General Public License or the Aladdin Free Public License, so read their license carefully if you want to redistribute the results of using their compiler.

Intel C/C++ environment

Intel provides a C/C++ compiler that is compatible with the Microsoft Visual C++ environment. The main advantage of this compiler over MSVC 5.0 and 6.0 is that it produces working code even when all optimizations are enabled and when stack checking is disabled.

To build Ghostscript using the Intel C/C++ compiler, you have to make the following small changes in the makefiles:

More specifically, use "TDEBUG=0" and set both "COMP" and "COMPAUX" to the full path of icl (for example "COMP=C:\intel\compiler45\bin\icl" if the Intel C/C++ compiler V4.5 was installed to C:\intel). It is suggested that you use a batch file to launch nmake, since the command line processes the "=" on its own. Also, you may need to execute vcvars32.bat and iccvars.bat to register the proper paths for the compiler, its include files and its libraries.

You can buy or download a 30-day evaluation version of the Intel C/C++ compiler from Intel's Software Performance Tools web site:

How to build Ghostscript from source (MacOS version)

Traditional MacOS

The Macintosh version of Ghostscript requires the Metrowerks Codewarrior development suite. Download the macgs-7xx-src.sit source archive from the location listed below. This includes a Codewarrior .mcp project file than can be used to build both Carbon and CFM versions of the ghostscript shared library component.

If your system doesn't automatically unpack the source archive, you can download the gratis Stuffit Expander to open it.

This archive includes appropriate versions of the jpeg, zlib and libpng 3rd party library source for convenience. You must still download the fonts and place them in an appropriate location, along with the contents of the lib directory from the source archive.

Note that since this is just a library component, you will need a front-end application, such as MacGSView, to actually view or convert postscript and pdf documents.


The unix source distribution (.tar.gz) builds fine on Darwin/MacOS X, albeit without a display device. You can generally just use the Makefile generated by ./configure or macosx.mak as your top-level makefile. This will allow you to use Ghostscript from the command line as a BSD-layer tool to rasterize postscript and pdf and convert between the various formats supported by Ghostscript.

There is also a support for building Ghostscript as a framework. This is a special encapsulated shared library format specific to MacOS X. To build the framework, copy macosx.mak to the top-level directory, rename it to makefile and issue 'make framework' from This will result in a Ghostscript.framework in the sobin directory. It must be manually copied to /Library/Frameworks/ before applications can use it. You may need to create the Frameworks/ directory on some systems.

Finally, there is a macos-mcp.mak makefile that can be used to set up the Codewarrior shared library component build described in the section on Classic MacOS above.

To set up the shlib build, download and uncompress the Ghostscript source. If the archive doesn't contain the 3rd party jpeg, png, and zlib source, you must download them as described at the beginning of this document and unpack them under the macgs-###-src directory under the specific names jpeg, zlib and libpng. You cannot use symlinks as Codewarrior will not be able to follow them for some of the needed header files.

Copy src/macos-mcp.mak to the top-level directory and rename it makefile. Then run 'make' in that directory, either from within or through Project Builder. This will set up the generated code required for the build and run a shell script to generate ghostscript.mcp.xml. Launch Metrowerks Codewarrior, and select 'Import Project...' from the File menu, and open the xml project file. When asked, save the results as ghostscript.mcp in the same directory and you should be ready to build the shared library component.

Tradtional ('PPC') applications based on the Code Fragment Manager will not be able to open the shlib linked with CarbonLib, so two targets are provided, one with carbon and one without.

How to build Ghostscript from source (Unix version)

Before issuing the make command to build Ghostscript, you have to make some choices, for instance

Be sure to check the sections on tool-, OS-, and hardware-specific issues for notes on your particular platform and compiler. In fact, that is the first place to check if you build Ghostscript and it crashes or produces obviously incorrect results.

The multi-architecture makefile

Especially if you are working in a Unix environment with multiple CPU types, operating systems, and/or C compilers, you may find the file all-arch.mak useful. This user-contributed file includes "wrappers" for the Unix makefiles for many different common environments. The author of this file notes:

This makefile allows you to execute

	 make `hostname`

on any machine on a network, without having to examine the Makefile for a specific target name. Also, some of the targets in the Makefile incorporate special changes in compiler options for certain files, to work around compiler bugs that Ghostscript has been so good at exposing. Having that special handling written down in a Makefile proves very convenient.

I don't do "make install" until I've done

	cd lib
	../bin/gs ../examples/

and verified that the famous tiger can be correctly displayed. Also, the "make install" step is careful to first remove any existing $(BINDIR)/gs, then install a new gs there with a hard link to gs-x.yz.

That way, each installation makes gs a synonym for the latest release, but earlier ones remain in place in case backtracking is needed, which I've fairly often wanted to do when investigating changed behavior, or a suspected bug.

When I've been experimenting with a new feature, such as GNU readline support, I change the setting of GS from gs to ngs (new gs), so as not to break any existing programs by the installation of an experimental version.

Setting up "makefile"

The files src/unix*.mak are the makefiles for Unix platforms, and you choose one based on what compiler you use. To build Ghostscript, however, you must use the simple command "make", which must find the file "makefile" (or "Makefile"). If your system supports symbolic links, set up "makefile" like this.

GNU gcc:      ln -s src/unix-gcc.mak makefile
Non-gcc ANSI C compiler:   ln -s src/unixansi.mak makefile

If your system doesn't support symbolic links, first finish all changes to the compiler-specific makefile, then make a hard link, omitting the -s switch.

The makefile distributed with Ghostscript selects the following devices to include in the build:

Devices included as distributed
Type    Devices

Display   X Windows
Printers   H-P DeskJets, LaserJets, and color DeskJets and PaintJets; Canon BubbleJets
File formats   Group 3 & Group 4 fax; JPEG; PCX; PBM, PGM, PKM, & PPM; TIFF; PostScript images; PNG; distilled PDF, PostScript, and EPS; PCL XL ("PCL 6")

The unix*.mak files explicitly compile and link the JPEG, PNG, and zlib libraries into the executable. If your Unix system already includes the PNG and zlib libraries -- probably in /usr/lib/libpng.{a,so} and /usr/lib/libz.{a,so} -- and you would rather use those copies, change the definition of SHARE_LIBPNG and SHARE_ZLIB from 0 to 1 in the relevant unix*.mak file before compiling. Note that if you do this, you will get non-debug versions of these libraries even if you selected DEBUG in the makefile. At the insistence of some users, we have also provided the ability to do this with the JPEG library (SHARE_JPEG), but should not use it: in order to be compatible with Adobe interpreters (which do not follow the JPEG standard exactly), Ghostscript has to compile the IJG code with the non-standard definition

#define D_MAX_BLOCKS_IN_MCU 64

and since shared versions of this library will not have been compiled this way, you will get errors on some valid PostScript and PDF input files. Note also that because not all the JPEG library header files that Ghostscript uses are normally installed in /usr/include, you must have the source code for this library available even if you set SHARE_JPEG to 1.

If the X11 client header files are located in some directory which your compiler does not automatically search, you must change the XINCLUDE macro in the makefile to include a specific -I switch. See the comment preceding XINCLUDE in the makefile.

Currently Ghostscript is set up to compile and link in a generic Unix environment. Some Unix environments may require changing the LDFLAGS macro in the makefile; be sure to check the Unix section for your specific tools, operating system, and hardware.

Ghostscript uses ANSI syntax for function definitions. Building with pre-ANSI C compilers is no longer supported.

Shared object

To build Ghostscript as a shared object with gcc (instead of as a single large executable) use:
	ln -s src/unix-gcc.mak makefile
	make so

This will build and two programs which use the shared object, gsx which uses Gtk+ and gsc which does not.

Do not use make -f src/unix-gcc.mak because this will break the recursive make used in building the shared object.

To install the shared object and these two programs:

	make soinstall
To delete files created by the build process:
	make soclean

For more details see unix-dll.mak.

Tool-specific issues

gcc 2.7.*

Some of the issues in using gcc are very specific to the particular computer, the particular version of the operating system, and the particular version of gcc available to you. You can check the version of gcc with the gcc --version command.

An optimizer bug in gcc versions 2.7.0, 2.7.1, and 2.7.2 causes the compiler to generate incorrect code. The makefile works around this, but we recommend that if possible you use either an earlier or a later version of gcc; for instance, gcc 2.5.8, gcc 2.6.3, or later which don't have this bug. Note, however, that gcc has other problems on some platforms, so please read the section for your specific platform.

GNU make

Current versions of GNU make have no problems, but GNU make 3.59 can't handle the final linking step in some cases; if this happens, use the platform's standard make, typically /bin/make.

OS-specific issues

386 Unix


Digital Unix (Alpha)


On FreeBSD systems, in the top-level makefile (unixansi.mak, unix-gcc.mak, change the value of STDLIBS from -lpthread -lm to -lc_r -lm before building.


You may want to create RPM (Red Hat Package Manager) files for Ghostscript. Because of the lack of standardization of installation directory names between GNU/Linux releases, Ghostscript does not come with any RPM specification files. You may wish to contact the following people who have created RPM spec files in the past:

Henri Gomez
Russell Lang
Cristian Gafton
Preston Brown

The following instructions may work for the Ghostscript 6.0x distributions, once you have RPM spec files that you believe are appropriate.

To create RPMs for Ghostscript N.NN:

Bruce Babcock <> has made available everything needed to build Ghostscript under Slackware 3.*, Red Hat 4.* and 5.*, and Debian 1.* and 2.0; the files include instructions and shell scripts to build and install Ghostscript, as well as all the source and font kits and patches needed:


SCO Unix/Xenix

SVR4 Unix

System V Unix platforms


Hardware-specific issues

Alpha with gcc

H-P Apollo

AT&T 7040 R3


DECStations with Ultrix

H-P RISC workstations

Intergraph Clipper


NCR 3550

Pyramid MIServer-S

See "AT&T 7040 R3".

IBM RS/6000 with AIX

Silicon Graphics

Users have had a lot of problems with the MIPSpro compilers on SGI systems. We recommend using gcc. If you do choose to use the MIPSpro compiler, please read the following carefully.




VAX with Ultrix

How to build Ghostscript from source (OS/2 version)

Note: This section was contributed by a user: please e-mail Hermann Ulrichskötter <> if you have questions or problems.

The following instructions are for building with emx 0.9d/Fix2. Be warned that with this version of gcc/emx, compiler optimization flags '-O' or '-O1' will produce non-working output.

Before compiling or linking, execute md bin and md obj in the gs directory to create the directories for the binaries.

First, build the standard configuration:

Now, if you wish, you can edit OS2.MAK to suit your needs, and then perform nmake -f .\src\os2.mak clean and then nmake -f .\src\os2.mak.

How to build Ghostscript from source (OpenVMS version)

The DECC6.2-003 compiler has an optimization problem that may lead to warnings about the "ANSI aliasing rules". DEC (Compaq) can provide a fix for this problem. The DECC6.2-006 compiler apparently does not have the problem.

DEC C runtime library versions 5.5 and newer have an exit function that is compatible with all other C systems, but some older ones don't. If you get error messages from VMS when auxiliary programs such as genarch or echogs finish executing, find the line in stdpre.h that reads

/*#define OLD_VMS_C*/
and remove the /* and */, changing it to
#define OLD_VMS_C

Some versions of DEC's X server have bugs that produce broad bands of color where dither patterns should appear, or characters displayed white on top of black rectangles or not displayed at all. If this happens, consult the usage documentation for how to work around X server bugs using X resources; also report the problem to DEC, or whomever supplied your X server.

You may also wish to turn off the use of a backing pixmap with Ghostscript, either to work around X server memory limitations or bugs, or to obtain faster displaying at the expense of no redrawing when a Ghostscript window is restored from an icon or exposed after being occluded by another window. Again, the usage documentation tells how to do this.

You can precompile any Type 1 font into C, then compile and build it into Ghostscript, as described in the fonts documentation. If you do this, then add "$(PSD)" to FEATURE_DEVS in OPENVMS.MAK:

$ FEATURE_DEVS = "$(PSD) $(PSD) $(PSD) $(PSD) $(PSD)"

Specify the font names with ccfonts1:

$ ccfonts1 = "Courier Courier_Oblique Courier_Bold Courier_BoldOblique"

If this makes the line too long, add another line of the same form, such as

$ ccfonts1 = "Courier Courier_Oblique Courier_Bold Courier_BoldOblique" $ ccfonts2 = "Times_Roman Times_Italic Times_Bold Times_BoldItalic"

Building with GNU make on OpenVMS

Note: GNU make on OpenVMS apparently has bugs that make it stop with an error when building Ghostscript version 5.80 or later. Until further notice, use MMS or MMK for building Ghostscript on OpenVMS. See below for details.

As of Ghostscript version 5.0 you can use GNU make -- with the file OPENVMS.MAK and some auxiliary .COM files -- to build Ghostscript on OpenVMS. Use the command:

make -fopenvms.mak "DECWINDOWS=[1.2]"

That is, specify either "1.2" or nothing (blank) as the value of DECWINDOWS. In Europe and other parts of the world where ISO standard paper sizes are used, append "A4_PAPER=1" to that line to make A4 the default paper size at run time.

If you haven't a prebuilt copy of GNU make, you'll have to build it yourself; as of Version 3.76 (but not earlier) it is said to build properly under OpenVMS on both VAX and Alpha. The kit is available at the Free Software Foundation's ftp site and its mirrors. See

Building with MMK or MMS on OpenVMS

As of Ghostscript version 5.68 you can use MMK or MMS to build Ghostscript on OpenVMS. MMS is a utility available from Compaq (Digital); MMK is a freely-available program largely compatible with MMS.

Building Ghostscript with MMK or MMS uses the file OPENVMS.MMK and some auxiliary .COM files. To build Ghostscript with MMK or MMS, use the command:

where ### is either mmk or mms.

Specify DECWINDOWS1_2=1 for DECWINDOWS 1.2, DECWINDOWS1_2=0 for other DECWINDOWS versions. In Europe and other parts of the world where ISO standard paper sizes are used, add ,"A4_PAPER=1" just before the final closing parenthesis to make A4 the default paper size at run time.

Other environments

Environments lacking multi-threading

All environments mentioned here by name have multi-threading capability. However, if your environment doesn't, you can remove all need for multi-threading by setting SYNC=nosync in the top-level makefile. Note that you will not be able to use any so-called "async" drivers (drivers that overlap interpretation and rasterization) if you do this. No such drivers are in the DEVICE_DEVS* lists of any makefile that we distribute.

Plan 9

Use unix-gcc.mak, editing it to define


You will also probably have to edit many path names.


David J. Hawkey Jr. writes that he built Ghostscript 4.03 and 5.0 under QNX 4.22, 4.23, and 4.24 using Watcom C 10.6 and that "it works quite well, after figuring out the /etc/config/lpsrvr directives, except for color printing to my HP DeskJet some-number-or-another". Here is a concise presentation of changes based on the ones he made for Ghostscript 4.03.

Original lines    Change to

INSTALL = install -c
  INSTALL = cp

datadir = $(prefix)/share   datadir = $(prefix)/lib



EXTRALIBS=   EXTRALIBS=-lXqnx_s -lsocket

XINCLUDE=-I/usr/local/X/include   #XINCLUDE=-I/usr/local/X/include

XLIBS=Xt Xext X11
XLIBS=Xt_s Xext X11_s

After the line
#include <sys/param.h>

add these lines:

#if defined(__QNX__)
#include <unix.h>

After the line
#include "time.h"

add these lines:

#if defined(__QNX__)
#include <sys/time.h>

Modify the line beginning
#  if defined(Plan9) ||

to begin

#  if defined(__QNX__) || defined(Plan9) ||
Here is Hawkey's lpsrvr as an example.
# lpsrvr
# Defines the print queues and their devices
# Queues

# ink-jet: Ghostscript interpreter for mono DeskJet - LaserJet works
#          better than DeskJet!

        co=/usr/local/bin/gs -q -sDEVICE=laserjet -sOutputFile=- -dNOPAUSE $(spfile) | cat > $(device)

# Devices



Copyright © 1996, 2000 Aladdin Enterprises. All rights reserved.

This software is provided AS-IS with no warranty, either express or implied. This software is distributed under license and may not be copied, modified or distributed except as expressly authorized under the terms of the license contained in the file LICENSE in this distribution.

Ghostscript version 7.07, 17 May 2003