Simple error using GD::Graph on Windows


M

Mr Hyde

Hi guys,

My apologies if this is a simple issue: I've been hacking away at it
for too long and have had no luck finding other people with the same
issue.

I have a very simple script named draw.pl:

---begin

use GD::Graph::bars;

my $graph = GD::Graph::bars->new(800, 600);

---end

cut down to isolate the issue. When I run the command

perl draw.pl

it comes up with the error

Can't locate object method "new" via package "GD::Image" at
D:/Perl/site/lib/GD/Graph.pm line 286.

I'm on a Windows XP box, running perl 5.8.6 from ActiveState. I've
installed the GD, GDTextUtil, GDGraph and GD-Convert modules via ppm.
There is no GDImage package or anything like that: I fetched them from
http://theoryx5.uwinnipeg.ca/ppms/ because ActiveState didn't have the
GD modules in their repository.

Any ideas? I'm sure it's something pretty simple, however I've only
worked with perl on Linux before.

The overall project is I want to be able to draw charts into a webpage
and include them in a C++ application, however I couldn't find a C++
API that allowed me to write chart images to file so I was going to
implement it in perl and include the perl scripts in the code. This GD
issue, irritatingly, is the first step in this plan. If anyone knows a
more straightforward way to do this, it would be greatly appreciated.

Thanks in advance

H
 
Ad

Advertisements

A

A. Sinan Unur

Hi guys,

My apologies if this is a simple issue: I've been hacking away at it
for too long and have had no luck finding other people with the same
issue.

I have a very simple script named draw.pl:

---begin

use GD::Graph::bars;

my $graph = GD::Graph::bars->new(800, 600);

---end

cut down to isolate the issue. When I run the command

perl draw.pl

it comes up with the error

Can't locate object method "new" via package "GD::Image" at
D:/Perl/site/lib/GD/Graph.pm line 286.

You need

use GD::Graph;

before

use GD::Graph::bars;

Sinan
 
M

Mr Hyde

You need

use GD::Graph;

before

use GD::Graph::bars;

Sinan

Thanks Sinan, though unfortunately that doesn't work. I've now got

use GD::Graph;
use GD::Graph::bars;

my $graph = GD::Graph::bars->new(800, 600);

however I still get the same error.
 
S

Sisyphus

Mr Hyde said:
Thanks Sinan, though unfortunately that doesn't work. I've now got

use GD::Graph;
use GD::Graph::bars;

my $graph = GD::Graph::bars->new(800, 600);

however I still get the same error.

What does line 286 of GD.pm say ? (Provide a few lines either side, for
context.)

Cheers,
Rob
 
M

Mr Hyde

What does line 286 of GD.pm say ? (Provide a few lines either side, for
context.)

Cheers,
Rob

I'm assuming you mean GD\Graph.pm. Line 286 (and the surrounding
segment) is


sub open_graph
{
my $self = shift;
return $self->{graph} if exists $self->{graph};

#This next line is 286
$self->{graph} = GD::Image->new($self->{width}, $self->{height});
}

Now my knowledge of perl is really quite limited, but should there be
a file Image.pm in my GD folder? There isn't, so is it spitting the
dummy because of that?

Hyde
 
S

Sisyphus

Mr Hyde said:
I'm assuming you mean GD\Graph.pm. Line 286 (and the surrounding
segment) is


sub open_graph
{
my $self = shift;
return $self->{graph} if exists $self->{graph};

#This next line is 286
$self->{graph} = GD::Image->new($self->{width}, $self->{height});
}

That should be ok, I think. GD.pm knows all about GD::Image objects, and
GD::Graph loads GD.pm .... so I'm not sure what's going on.

Does the following run without error for you:

use GD;
$im = GD::Image->new(800, 800);
print "OK\n";
__END__

If so, then maybe you just need to "use GD;" at the start of your script
...... though why that should be necessary eludes me.

Cheers,
Rob
 
Ad

Advertisements

M

Mr Hyde

Does the following run without error for you:

use GD;
$im = GD::Image->new(800, 800);
print "OK\n";
__END__

If so, then maybe you just need to "use GD;" at the start of your script
..... though why that should be necessary eludes me.

Cheers,
Rob

Problem solved! It appears the problem was that it couldn't find the
GD library, not sure why. I added

use lib "/Perl/site/lib";

above the "use GD;" line and it worked fine. Now I was under the
impression it would have added its own library to the path when it
installed, but I guess not.

Thanks for all your help.
 
S

Sisyphus

Mr Hyde said:
Problem solved! It appears the problem was that it couldn't find the
GD library, not sure why. I added

use lib "/Perl/site/lib";

above the "use GD;" line and it worked fine. Now I was under the
impression it would have added its own library to the path when it
installed, but I guess not.

Odd. I would have thought that "/Perl/site/lib" was already in @INC - in
which case the "use lib ..." line would achieve nothing.
Run "perl -V". That will show you, at the end of the output, the directories
that are in @INC. Any module in any of the specified directories *should* be
found automatically.

Cheers,
Rob
 
Ad

Advertisements

M

Mr Hyde

Odd. I would have thought that "/Perl/site/lib" was already in @INC - in
which case the "use lib ..." line would achieve nothing.
Run "perl -V". That will show you, at the end of the output, the directories
that are in @INC. Any module in any of the specified directories *should* be
found automatically.

Cheers,
Rob

Well, the output was

@INC:
D:/Perl/lib
D:/Perl/site/lib
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top