Here's the deal: I'm trying to make a CGI proggy that generates images on the fly.  I'm making a chat thats kinda like walking around in a sort of area.  The characters will be fully colour customised.   I had a set of 7 colours, with a special colour for the skin.  The way I had it sorted was that I would have a file for each conceivable combination, but this would result in some 28,000 files.  This way would allow me to allow all possible colours.

The script is composed of two parts: a CGI wrapper and the actual script that generates the colours.  The wrapper is currently being used for debugging, but will support the output when i am assured that the program will work in CGI mode.  The wrapper sets LD_LIBRARY_PATH, as the libs I need are not in their proper places and I can't put them there, as I am not root.

Here is the code for the wrapper:
---

#!/bin/sh

echo "Content-type: text/plain"
echo ""

echo "Setting initial values"

PATHIN=/export/student/home/amason09/usr/lib
#PATHIN=`pwd`
#PATHIN=

LD_LIBRARY_PATH=$PATHIN:/lib:/usr/lib:/usr/local/lib:.
export LD_LIBRARY_PATH

echo "LD Lib path set to $LD_LIBRARY_PATH"

echo "Now loading the program"

./test.tcl 2>&1

echo "Program run."

---

And this is the code for the actual script:
--

#!/usr/local/bin/tclsh8.3

proc debug {msg} {
  puts  $msg
}

debug "loading module... ld lib path is $env(LD_LIBRARY_PATH)"
load ./Gdtclft2.2.so
debug "module loaded..."

puts "Content-type: image/png\n"

################################################################
# Sample gdtcl program
#
# Create a 64 x 64 image
set im [gd create 64 64]

# Get black and white as colors.  Black is the background color because
# it is allocated first from a new image.

set black [gd color new $im 0 0 0]
set white [gd color new $im 255 255 255]

# Draw a line from upper left to lower right
gd line $im $white 0 0 63 63

# Open a file for writing (Tcl on Unix, at least, doesn't support 'wb' mode)
set out [open test.png w]

# Output the image to the disk file
gd writePNG $im $out

# Close the file
close $out

# Destroy the image in memory
gd destroy $im

---

(the output will come later)

The problem is, when I try to run it in the console, it works fine:
---
Content-type: text/plain

Setting initial values
LD Lib path set to /export/student/home/amason09/usr/lib:/lib:/usr/lib:/usr/local/lib:.
Now loading the program
loading module... ld lib path is /export/student/home/amason09/usr/lib:/lib:/usr/lib:/usr/local/lib:.
module loaded...
Content-type: image/png

Program run.
---

But when I run it under CGI:
---
Setting initial values
LD Lib path set to /export/student/home/amason09/usr/lib:/lib:/usr/lib:/usr/local/lib:.
Now loading the program
loading module... ld lib path is /export/student/home/amason09/usr/lib:/lib:/usr/lib:/usr/local/lib:.
couldn't load file "./Gdtclft2.2.so": ld.so.1: /usr/local/bin/tclsh8.3: fatal: libgd.so.2: open failed: No such file or directory
    while executing
"load ./Gdtclft2.2.so"
    (file "/dev/fd/4" line 8)
Program run.
---

Am I doing something wrong?  I can't see where I could be going wrong...

Note: The image_create.cgi file is set to suid.