This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

How to write minimal program using GD library


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?


Thanks
Siegfried


/***
 *  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 MSVCDir=%VCINSTALLDIR%\VC7
 *  SET FrameworkDir=\WINNT\Microsoft.NET\Framework
 *  SET FrameworkSDKDir=\Program Files\Microsoft Visual Studio
.NET\FrameworkSDK
 *  set
PATH=%MSVCDir%\BIN;%VCINSTALLDIR%\Common7\Tools;%VCINSTALLDIR%\Common7\IDE;%
VCINSTALLDIR%\Common7\Tools\bin\prerelease;%VCINSTALLDIR%\Common7\Tools\bin;
%FrameworkSDKDir%\bin
 *  set
INCLUDE=%MSVCDir%\ATLMFC\INCLUDE;%MSVCDir%\INCLUDE;%MSVCDir%\PlatformSDK\inc
lude\prerelease;%MSVCDir%\PlatformSDK\include;%FrameworkSDKDir%\include;%INC
LUDE%
 *  set
LIB=%MSVCDir%\ATLMFC\LIB;%MSVCDir%\LIB;%MSVCDir%\PlatformSDK\lib\prerelease;
%MSVCDir%\PlatformSDK\lib;%FrameworkSDKDir%\lib;%LIB%
 *  cl gddemo.c   /I. /c /MLd /W3 /Gm /GX /ZI /Od /D WIN32 /D _DEBUG /D
_CONSOLE /D _MBCS /FD /GZ /GR /D NOPROMPT
 *  cl gddemo.obj bgd.lib /link /out:gddemo.exe  /subsystem:console
/incremental:yes 
 *  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 http://www.boutell.com/gd/manual2.0.33.html#getgd
// http://www.boutell.com/gd/

/* 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. */
  fclose(pngout);
  fclose(jpegout);

  /* Destroy the image in memory. */
  gdImageDestroy(im);
}



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]