Perl的GD模块无法安装。

4

我正在努力弄清楚为什么无法在我的Debian 7服务器上安装GD Perl模块。这是我安装核心内容的方法:

sudo apt-get install libgd-gd2-perl

然后运行-MCPAN进行安装,我得到了以下结果:

root@myserver:~# sudo perl -MCPAN -e 'install GD'
Going to read '/root/.cpan/Metadata'
  Database was generated on Sun, 19 Jul 2015 21:41:02 GMT
Running install for module 'GD'
Running make for L/LD/LDS/GD-2.56.tar.gz
Checksum for /root/.cpan/sources/authors/id/L/LD/LDS/GD-2.56.tar.gz ok

  CPAN.pm: Going to build L/LD/LDS/GD-2.56.tar.gz

Configuring for libgd version 2.0.36.
Checking for stray libgd header files...none found.

Unknown option: installdirs
Usage: perl Build.PL [options]

Configure GD module.

 Options:
     -options       "JPEG,FT,PNG,GIF,XPM,ANIMGIF"   feature options, separated by commas
     -lib_gd_path   path            path to libgd
     -lib_ft_path   path            path to Freetype library
     -lib_png_path  path            path to libpng
     -lib_jpeg_path path            path to libjpeg
     -lib_xpm_path  path            path to libxpm
     -lib_zlib_path path            path to libpng
     -ignore_missing_gd             Ignore missing or old libgd installations and try to compile anyway

If no options are passed on the command line.  The program will
attempt to autoconfigure itself with the gdlib-config program (present
in GD versions 2.0.27 or later).  Otherwise it will prompt for these
values interactively.
Warning: No success on command[/usr/bin/perl Build.PL --installdirs site]
  LDS/GD-2.56.tar.gz
  /usr/bin/perl Build.PL --installdirs site -- NOT OK
Running Build test
  Make had some problems, won't test
Running Build install
  Make had some problems, won't install
Could not read metadata file. Falling back to other methods to determine prerequisites

我已经做了很多搜索,但似乎没有什么可以解决它。有什么建议吗?


2
你是否安装了底层的libgd软件包?GD.pm是其外部包装。 - Andy Lester
3
apt-get install libgd-gd2-perl 没有安装 Perl 模块吗?通常以 -perl 结尾的软件包会安装相应的 Perl 模块,因此我不认为您需要使用 CPAN。请注意,翻译后的内容已经尽可能保持原意,并且更加通俗易懂,但未进行解释或添加其他信息。 - ThisSuitIsBlackNot
这与缺少底层库没有任何关系。另外两个显然错过了错误消息:**未知选项:installdirs 用法:perl Build.PL [options]**。cpan期望Build.PL将其参数传递给Module::Build,但是GD有一个奇怪的Build.PL。稍后回答。 - ikegami
谢谢大家的回复。现在我感觉自己像个傻瓜!由于某种原因,$string是空的(仍然需要调试为什么这样,因为在旧服务器上它运行得很好)。因此,当它尝试通过perl脚本输出png图像时,它是空的(所以我得到了一个错误)。扇自己一巴掌!!! - Andrew Newby
以后参考,如果您在代码中使用的模块未安装或perl无法找到它,您将收到“Can't locate Foo/Bar.pm in @INC”的错误提示;听起来您遇到了不同的错误。 - ThisSuitIsBlackNot
2个回答

5
您遇到的错误是:
Unknown option: installdirs
Usage: perl Build.PL [options]

cpan希望Build.PL将其参数传递给Module::Build,但GD的Build.PL有点奇怪。让我们“修复”它。

从临时目录执行以下操作:

wget http://search.cpan.org/CPAN/authors/id/L/LD/LDS/GD-2.56.tar.gz
  -or-
curl -L http://search.cpan.org/CPAN/authors/id/L/LD/LDS/GD-2.56.tar.gz >GD-2.56.tar.gz

tar xvzf GD-2.56.tar.gz
cd GD-2.56
perl -i~ -pE'say "Getopt::Long::Configure(qw( pass_through ));" if /GetOptions/;' Build.PL
/usr/bin/perl Build.PL --installdirs site
sudo ./Build.PL installdeps
./Build.PL make
./Build.PL test
sudo ./Build.PL install

感谢您抽出时间回复。我将标记您为有效,因为我认为这应该已经解决了我的问题(我找到了一些帖子,其中说要“修复”Build.PL文件-但从未提供任何有关如何操作的信息!)。无论如何,我认为我必须在某个时候安装了某些东西,因为现在它可以工作<G>。 - Andrew Newby
1
ikegami - 正在尝试在一个dev服务器上运行这个程序(因为我要升级到Debian 8.1),但它似乎在perl -i~ -pE'say "Getopt::Long::Configure(qw( pass_through ));" if /GetOptions/;" Build.PL处卡住了,只显示下一行的>,这是在等待更多的命令吗? - Andrew Newby
有什么想法吗?我被卡在这个服务器上,直到我能够让GD运行起来:( - Andrew Newby
1
双引号应该是单引号。已修复。 - ikegami
1
谢谢@ikegami - 我成功地使用apt-get install libgd2-xpm-dev来解决问题,因为它似乎安装正常 :) - Andrew Newby

4
在Ubuntu 15.04中,需要对上述的智能答案进行轻微修改,才能使其安装GD。这样可以让'cpan'程序安装GD,然后再安装例如Image::Resize (使用GD)等模块。我在之后进行了操作。
sudo -i

在终端中运行,在进入一个临时文件夹后使用'cd'命令。首先,我做了这个操作,不管有没有用。

apt-get install libgd-dev

然后就是以下内容,它可能包含一个或多个冗余行,但是它能够正常工作:

wget http://search.cpan.org/CPAN/authors/id/L/LD/LDS/GD-2.56.tar.gz
tar xvzf GD-2.56.tar.gz
cd GD*
perl -i~ -pE'say "Getopt::Long::Configure(qw( pass_through ));" if /GetOptions/;' Build.PL
/usr/bin/perl Build.PL --installdirs site
chmod 755 Build.PL
./Build.PL installdeps
./Build installdeps
./Build test
./Build install

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接