Answer

问题及解答

安装Perl后如何添加模块?

Posted by haifeng on 2021-10-25 10:01:21 last update 2024-09-12 16:53:26 | Edit | Answers (1)

比如现在需要在 Perl 中使用 ImageMagick, 在 .pl 文件中通常要写

use Image::Magick;

也就是启用 Image::Magick 模块. 如果 Perl 是默认安装的, 则不会预先安装此模块. 在执行 .pl 文件时, 会提示下面的信息

 

Can't locate Image/Magick.pm in @INC (you may need to install the Image::Magick module) (@INC contains: C:/Strawberry/perl/site/lib C:/Strawberry/perl/vendor/lib C:/Strawberry/perl/lib) at test.pl line 6.
BEGIN failed--compilation aborted at test.pl line 6.


如果安装的是 strawberry Perl, 则已经安装了 cpanm. 在 Windows 下可以通过 where cpanm 查看其是否能直接调用.

然后通过 

cpanm Module::Name

直接安装需要的模块. 模块可以在 CPAN 网上查找.

例如: 在命令符窗口下键入 cpanm Image::Magick  就可以安装 Image::Magick 模块.

 

cpanm Image::Magick
--> Working on Image::Magick
Fetching http://www.cpan.org/authors/id/J/JC/JCRISTY/Image-Magick-7.0.11-3.tar.gz ... OK
Configuring Image-Magick-7.0.11-3 ... OK
Building and testing Image-Magick-v7.0.11 ... FAIL
! Installing Image::Magick failed. See C:\Users\haife\.cpanm\work\1635127678.42820\build.log for details. Retry with --force to force install it.

 

 


键入 perl -MCPAN -e shell 可进入 CPAN 的 shell 模式

 

perl -MCPAN -e shell
Unable to get Terminal Size. The Win32 GetConsoleScreenBufferInfo call didn't work. The COLUMNS and LINES environment variables didn't work. at C:\Strawberry\perl\vendor\lib/Term/ReadLine/readline.pm line 410.

cpan shell -- CPAN exploration and modules installation (v2.28)
Enter 'h' for help.

cpan>

1

Posted by haifeng on 2021-10-25 10:42:29

安装出错

 

cpan -i Image::Magick
Loading internal logger. Log::Log4perl recommended for better logging
CPAN: CPAN::SQLite loaded ok (v0.219)
CPAN: LWP::UserAgent loaded ok (v6.52)
Fetching with LWP:
http://cpan.strawberryperl.com/authors/01mailrc.txt.gz
CPAN: YAML::XS loaded ok (v0.82)
Fetching with LWP:
http://cpan.strawberryperl.com/modules/02packages.details.txt.gz
Fetching with LWP:
http://cpan.strawberryperl.com/modules/03modlist.data.gz
Creating database file ... Done!
Running install for module 'Image::Magick'
Fetching with LWP:
http://cpan.strawberryperl.com/authors/id/J/JC/JCRISTY/Image-Magick-7.0.11-3.tar.gz
CPAN: Digest::SHA loaded ok (v6.02)
Fetching with LWP:
http://cpan.strawberryperl.com/authors/id/J/JC/JCRISTY/CHECKSUMS
CPAN: Compress::Zlib loaded ok (v2.1)
Checksum for C:\STRAWB~1\cpan\sources\authors\id\J\JC\JCRISTY\Image-Magick-7.0.11-3.tar.gz ok
CPAN: Archive::Tar loaded ok (v2.38)
CPAN: CPAN::Meta::Requirements loaded ok (v2.140)
CPAN: CPAN::Meta loaded ok (v2.150010)
Configuring J/JC/JCRISTY/Image-Magick-7.0.11-3.tar.gz with Makefile.PL
Gonna create 'libMagickCore.a' from 'C:\Program Files\ImageMagick\ImageMagick-7.0.10-Q16-HDRI\CORE_RL_MagickCore_.dll'
Checking if your kit is complete...
Looks good
Generating a gmake-style Makefile
Writing Makefile for Image::Magick
Writing MYMETA.yml and MYMETA.json
  JCRISTY/Image-Magick-7.0.11-3.tar.gz
  C:\Strawberry\perl\bin\perl.exe Makefile.PL -- OK
Running make for J/JC/JCRISTY/Image-Magick-7.0.11-3.tar.gz
CPAN: Module::CoreList loaded ok (v5.20210123)
cp Magick.pm blib\lib\Image\Magick.pm
AutoSplitting blib\lib\Image\Magick.pm (blib\lib\auto\Image\Magick)
Running Mkbootstrap for Magick ()
"C:\Strawberry\perl\bin\perl.exe" -MExtUtils::Command -e chmod -- 644 "Magick.bs"
"C:\Strawberry\perl\bin\perl.exe" -MExtUtils::Command::MM -e cp_nonempty -- Magick.bs blib\arch\auto\Image\Magick\Magick.bs 644
"C:\Strawberry\perl\bin\perl.exe" "C:\Strawberry\perl\lib\ExtUtils/xsubpp"  -typemap C:\STRAWB~1\perl\lib\ExtUtils\typemap -typemap C:\STRAWB~1\cpan\build\Image-Magick-7.0.11-0\typemap  Magick.xs > Magick.xsc
"C:\Strawberry\perl\bin\perl.exe" -MExtUtils::Command -e mv -- Magick.xsc Magick.c
gcc -c  -I"C:\Program Files\ImageMagick\ImageMagick-7.0.10-Q16-HDRI\include" -DWIN32 -DWIN64 -D__USE_MINGW_ANSI_STDIO -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -fwrapv -fno-strict-aliasing -mms-bitfields -s -O2   -DVERSION=\"7.0.11\" -DXS_VERSION=\"7.0.11\"  "-IC:\STRAWB~1\perl\lib\CORE"  -D_LARGE_FILES=1 -DHAVE_CONFIG_H Magick.c
Magick.xs: In function 'XS_Image__Magick_Mogrify':
Magick.xs:11596:18: warning: implicit declaration of function 'WhiteBalanceImage'; did you mean 'SteganoImage'? [-Wimplicit-function-declaration]
           (void) WhiteBalanceImage(image,exception);
                  ^~~~~~~~~~~~~~~~~
                  SteganoImage
Magick.xs:11625:17: warning: implicit declaration of function 'BilateralBlurImage'; did you mean 'RotationalBlurImage'? [-Wimplicit-function-declaration]
           image=BilateralBlurImage(image,(size_t) geometry_info.rho,(size_t)
                 ^~~~~~~~~~~~~~~~~~
                 RotationalBlurImage
Magick.xs:11625:16: warning: assignment to 'Image *' {aka 'struct _Image *'} from 'int' makes pointer from integer without a cast [-Wint-conversion]
           image=BilateralBlurImage(image,(size_t) geometry_info.rho,(size_t)
                ^
Magick.xs:11633:18: warning: implicit declaration of function 'SortImagePixels'; did you mean 'CopyImagePixels'? [-Wimplicit-function-declaration]
           (void) SortImagePixels(image,exception);
                  ^~~~~~~~~~~~~~~
                  CopyImagePixels
"C:\Strawberry\perl\bin\perl.exe" -MExtUtils::Mksymlists \
     -e "Mksymlists('NAME'=>\"Image::Magick\", 'DLBASE' => 'Magick', 'DL_FUNCS' => {  }, 'FUNCLIST' => [], 'IMPORTS' => {  }, 'DL_VARS' => []);"
g++ Magick.def -o blib\arch\auto\Image\Magick\Magick.xs.dll -mdll -s -L"C:\STRAWB~1\perl\lib\CORE" -L"C:\STRAWB~1\c\lib" -L"C:/STRAWB~1/cpan/build/Image-Magick-7.0.11-0" -L"C:\Program Files\ImageMagick\ImageMagick-7.0.10-Q16-HDRI\lib"  Magick.o   "C:\STRAWB~1\perl\lib\CORE\libperl532.a" "libMagickCore.a" "C:\STRAWB~1\c\x86_64-w64-mingw32\lib\libmoldname.a" "C:\STRAWB~1\c\x86_64-w64-mingw32\lib\libkernel32.a" "C:\STRAWB~1\c\x86_64-w64-mingw32\lib\libuser32.a" "C:\STRAWB~1\c\x86_64-w64-mingw32\lib\libgdi32.a" "C:\STRAWB~1\c\x86_64-w64-mingw32\lib\libwinspool.a" "C:\STRAWB~1\c\x86_64-w64-mingw32\lib\libcomdlg32.a" "C:\STRAWB~1\c\x86_64-w64-mingw32\lib\libadvapi32.a" "C:\STRAWB~1\c\x86_64-w64-mingw32\lib\libshell32.a" "C:\STRAWB~1\c\x86_64-w64-mingw32\lib\libole32.a" "C:\STRAWB~1\c\x86_64-w64-mingw32\lib\liboleaut32.a" "C:\STRAWB~1\c\x86_64-w64-mingw32\lib\libnetapi32.a" "C:\STRAWB~1\c\x86_64-w64-mingw32\lib\libuuid.a" "C:\STRAWB~1\c\x86_64-w64-mingw32\lib\libws2_32.a" "C:\STRAWB~1\c\x86_64-w64-mingw32\lib\libmpr.a" "C:\STRAWB~1\c\x86_64-w64-mingw32\lib\libwinmm.a" "C:\STRAWB~1\c\x86_64-w64-mingw32\lib\libversion.a" "C:\STRAWB~1\c\x86_64-w64-mingw32\lib\libodbc32.a" "C:\STRAWB~1\c\x86_64-w64-mingw32\lib\libodbccp32.a" "C:\STRAWB~1\c\x86_64-w64-mingw32\lib\libcomctl32.a" -Wl,--enable-auto-image-base
Magick.o:Magick.c:(.text+0xe6c6): undefined reference to `BilateralBlurImage'
Magick.o:Magick.c:(.text+0xe7af): undefined reference to `SortImagePixels'
Magick.o:Magick.c:(.text+0xf4bd): undefined reference to `WhiteBalanceImage'
collect2.exe: error: ld returned 5 exit status
gmake: *** [Makefile:487: blib\arch\auto\Image\Magick\Magick.xs.dll] Error 1
  JCRISTY/Image-Magick-7.0.11-3.tar.gz
  C:\STRAWB~1\c\bin\gmake.exe -- NOT OK
Stopping: 'install' failed for 'Image::Magick'.