How to write minimal program using GD library

Siegfried Heintze
Sat Jun 18 05:35:00 GMT 2005

I'm looking at the GD documentation (a C graphics library) and it pointed me
to a simple minimal C program. I cut and pasted this. See below.

I cannot get it to work, however, with g++ or msvc v7. When I follow the
directions with gcc, it compiles and links fine but when I try to run the
resulting program, I get the following error:

This application has failed to start because cygXpm-4.dll was not found.
Re-installing the application may fix this problem.

I've downloaded nearly the entirety of Cygwin and I cannot find such a dll.
How do I make this minimal program work?

When linking with C libraries downloaded as part of Cygwin, do I have to do
anything special? The documentation says no. I would guess that gcc
automatically knows to look in C:\cygwin\lib -- is this correct?


 *  Begin commands to execute this file using g++ with bash
 *  gcc gddemo.c -o gddemo.exe -lgd
 *  cygpath gddemo.exe 
 *  ./gddemo.exe <<EOF
 *  insert your data here
 *  EOF
 *  #rm gddemo.exe 
 *  End commands to execute this file using g++ with bash
 *  Begin commands to execute this file using MSVC7 with CMD.EXE
 *  SET VCINSTALLDIR=c:\Program Files\Microsoft Visual Studio .NET 2003
 *  SET FrameworkDir=\WINNT\Microsoft.NET\Framework
 *  SET FrameworkSDKDir=\Program Files\Microsoft Visual Studio
 *  set
 *  set
 *  set
 *  cl gddemo.c   /I. /c /MLd /W3 /Gm /GX /ZI /Od /D WIN32 /D _DEBUG /D
 *  cl gddemo.obj bgd.lib /link /out:gddemo.exe  /subsystem:console
 *  gddemo.exe "insert your data here" 
 *  del gddemo.obj gddemo.exe *.ilk *.pdb *.idb
 *  End commands to execute this file using MSVC7 with CMD.EXE
// See

/* Bring in gd library functions */

#include "gd.h"

/* Bring in standard I/O so we can output the PNG to a file */
#include <stdio.h>

int main() {
  /* Declare the image */
  gdImagePtr im;
  /* Declare output files */
  FILE *pngout, *jpegout;
  /* Declare color indexes */
  int black;
  int white;

  /* Allocate the image: 64 pixels across by 64 pixels tall */
  im = gdImageCreate(64, 64);

  /* Allocate the color black (red, green and blue all minimum).
    Since this is the first color in a new image, it will
    be the background color. */
  black = gdImageColorAllocate(im, 0, 0, 0);  

  /* Allocate the color white (red, green and blue all maximum). */
  white = gdImageColorAllocate(im, 255, 255, 255);  
  /* Draw a line from the upper left to the lower right,
    using white color index. */
  gdImageLine(im, 0, 0, 63, 63, white);  

  printf("call gdImageLine\n");

  /* Open a file for writing. "wb" means "write binary", important
    under MSDOS, harmless under Unix. */
  pngout = fopen("test.png", "wb");

  printf("call fopen\n");

  /* Do the same for a JPEG-format file. */
  jpegout = fopen("test.jpg", "wb");
  printf("call gdImgPng\n");

  /* Output the image to the disk file in PNG format. */
  gdImagePng(im, pngout);

  /* Output the same image in JPEG format, using the default
    JPEG quality setting. */
  gdImageJpeg(im, jpegout, -1);

  /* Close the files. */

  /* Destroy the image in memory. */

Unsubscribe info:
Problem reports:

More information about the Cygwin mailing list