Linux使用CPAN模塊自動安裝
安裝前需要先聯上線,並且要取得root權限。
perl -MCPAN -e shell
獲得幫助
cpan>h
列出CPAN上所有模塊的列表
cpan>m
根據關鍵字在CPAN上查找某個模塊:
cpan[1]> i /scws/
安裝模塊
cpan>install DBI
自動完成DBI模塊從下載到安裝的全過程。
退出
cpan>q
手動編譯Perl模塊
具體步驟: 1 安裝編譯器 2 設置編譯器的環境變量 3 可能安裝dmake
具體方法:
1. 首先要有個c編譯器,推薦dev-cpp(開源免費的, http://umn.dl.sourceforge.net/sourceforge/dev-cpp/devcpp4990setup.exe ),記得要下含有mingw的就是了(下載含有mingw的,因為這個版本的bin目錄里有gcc.exe等工具).
1.1 安裝好了編譯器之后,要能在cmd中以命令方式運行的話,必須要設置環境變量, 在winxp中[我的電腦]->[屬性]->[高級]->[環境變量]里設置,只需要在path里加個你路徑,比如你的安裝路徑是c:\dev-cpp,那你就要加上c:\dev-cpp\bin (path中有很多其他的路徑,之間記得用;隔開)弄完好,重啟電腦,在cmd中運行gcc -v 顯示出內容表示編譯器安裝成功,並且可以用命令行編譯.
2. 編譯步驟,在cpan上下載需要的模塊,比如Win32::SerialPort,下載好了解壓,在cmd中進入這個目錄,就用常見的方法:
perl Makefile.pl
make
make test
make install
2.1 需要注意幾點
2.1.1 具體編譯步驟應該先看下模塊包內的readme
2.1.2 用的是dev-pp編譯器,故用make,vc編譯器好象是nmake
2.1.3 最重要的是,使用make很可能會出現錯誤,不能編譯,找了很多原因,有高人介紹了解決辦法,就是下載一個叫dmake的工具(
http://search.cpan.org/CPAN/authors/id/S/SH/SHAY/dmake-4.12-20090907-SHAY.zip
),下載后解壓縮,將里面的dmake.exe和startup的文件夾一起復制到c:\dev-cpp\bin 里(因為這個目錄注冊到環境變量里的),之后安裝改成:
perl Makefile.pl
dmake
dmake test
dmake install
ref:
http://blog.csdn.net/runandrun/article/details/6010840
http://hi.baidu.com/opcbo/blog/item/07801e2a02dd9d195243c110.html
windows xp下perl cpan模塊安裝及問題解決
關於這個主題網上有些教程,對的,錯的都有。如果將這些對的,錯的方法都試一遍的話,你就會發現結果往往是令人郁悶的。對於習慣了windows的用戶,perl MakeFile.PL、make、make install的標准3步操作和給出的提示猶如天書。
現在我就將我嘗試過的方法,以及出現的結果,最終的解決方法簡介如下,整個過程以Coro模塊為例子。
所用的perl為:ActiveState perl 5.10
1,下載Coro模塊,解壓縮。目錄中最好不要出現空格,中文字符,避免出現問題。
2,dos下進入該目錄,運行命令:perl makefile.pl
3,注定是要失敗的,因為該模塊是xs模塊。需要配置一個C/C++ compiler(C/c++編譯器環境)。
提示:It looks like you don't have a C compiler on your PATH, so you will not be able to compile C or XS extension modules.
4,有文章推薦用Microsoft visual c++ 2005 express edition 大小462M左右。下載,安裝,還要運行vsvarsall.bat來設置環境變量,驗證環境變量設置是否成功的方法:在dos下直接鍵入cl,然后按回車,如果返回該命令的一些提示,那就設置正確了。還要下載nmake.exe,運行nmake.exe,會生成兩個文件:nmake15.exe和NMAKE.ERR。將這兩個文件復制到perl安裝目錄的bin文件夾中。
5,運行步驟2的命令,然后運行命令:nmake。提示windows.h文件找不到,原來是需要SDK配合。哎,真煩,放棄了這條路。
6,卸載VC 2005。同時把環境變量path里不需要的一些路徑給清理了。
7,下載DEV-C++ 5,大小只有10幾M。
8,安裝它,在命令行下輸入:gcc -v 返回結果如下:
Reading specs from C:/Perl/dev_cpp/DEV-CPP/Bin/../lib/gcc/mingw32/3.4.2/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=
mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable
-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --e
nable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-ja
va-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchroniz
ation --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.2 (mingw-special)
9,安裝dmake。直接在命令行里面輸入:ppm install dmake。安裝成功。命令行輸入dmake -V。注意是大寫的V,返回結果:
dmake.exe - Version 4.11-20080107-SHAY (Windows / MS Visual C++)
Copyright (c) 1990,...,1997 by WTI Corp.
Default Configuration:
MAXLINELENGTH := 32766
MAXPROCESSLIMIT := 4
MAXPROCESS := 1
.IMPORT .IGNORE: DMAKEROOT
.MAKEFILES : makefile.mk makefile
.SOURCE : .NULL
DMAKEROOT *= $(ABSMAKECMD:d)startup
MAKESTARTUP := $(DMAKEROOT)\startup.mk
Please read the NEWS file for the latest release notes.
10,命令行下進入coro的目錄,運行命令:perl makefile.pl
11,命令行下輸入:dmake。返回:
dmake.exe: Error: -- `C:\Perl\libConfig.pm' not found, and can't be made
一番搜索之后,有人建議將模塊目錄中makefile(native下的文件)文件里面的DIRFILESEP = ^\改成DIRFILESEP = \\
改完之后,再次dmake。又有問題:
dmake.exe: Error executing 'rem': No such file or directory
dmake.exe: Error code 255, while making 'blibdirs'
神啊,這是為什么啊?
又是一番搜索,仿佛找到了蛛絲馬跡。命令行下運行:perl -MConfig -e "print $Config{make}"
結果返回:nmake , 手工刪除該nmake.exe文件。
原來這就是問題所在。dev-cpp里面的應該是dmake的,而vc之類的是nmake的。所以趕緊的把perl\bin目錄里面的nmake15.exe和nmake.err文件給刪了。
再運行:perl -MConfig -e "print $Config{make}"
返回:dmake
終於對了。
12,然后就是重新perl makefile.pl
13,dmake
14,dmake test
15,dmake install
安裝成功!
【出處http://hi.baidu.com/qkgztdd】
g++.exe -c -nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STR ICT -DPERL_TEXTMODE_SCRIPTS -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_I MPLICIT_SYS -DUSE_PERLIO -D_USE_32BIT_TIME_T -MD -Zi -DNDEBUG -O1 -DVERS ION=\"\" -DXS_VERSION=\"\" "-IC:\Perl\lib\CORE" Distributions.cxx
g++.exe: unrecognized option `-nologo'
g++.exe: unrecognized option `-GF'
g++.exe: unrecognized option `-Zi'
g++.exe: unrecognized option `-Zi'
cc1plus.exe: error: unrecognized option `-W3'
dmake.exe: Error code 129, while making 'Distributions.obj'
dmake: Error code 255, while making 'subdirs'
------------------------------------------------------------------------
As Rob suggested I tried to overwrite my Active Perl install because it's configuration was odd, and this fixed some of the problems but now when I ask about Perl C compiler it gives me the full path E:/xampp/perl/site/bin/gcc.exe instead of just 'gcc' and surprisingly when I open Config_heavy.pl file I can't find that anywhere, my Config_heavy says cc:'gcc' so why Perl gives compiler with full path?? I guess Perl is using another file for detecting configurations, I really couldn't find where is that so I had to make some of my usual hacks :P here is what I did maybe this can help someone, but in all this is not a recommended method to get Inline working unless you're really really know what you're doing and you used every method suggested by the Inline list who really know what they are doing unlike me :))
Here is what I did After installing ActivePerl Mingw package
ppm install Mingw
I downloaded strawberry zipped package (Not installer) then unpacked it, make sure to download the same version of your Active Perl version, in my situation it's Perl 5.10
I copied c folder from strawberry and placed it in the same folder where my Perl folder resides
I copied strawberry/perl/lib/Core folder and placed it in my ActivePerl/lib folder, this will ask you to replace the current CORE folder just accept to replace all
Then I opened strawberry/perl/lib/Config_heavy.pl file replaced all C:/strawberry/Perl with my ActivePerl location, in my case it's E:/xampp/Perl then saved Config_heavy and placed it in E:/xampp/Perl/lib, this will ask you to overwrite the current Config_heavy.pl accept that and you're done
Please remember to back up your Perl folder before doing this so if any odd behavior you can delete and place the backup again and try something else, I always do that
Now after trying my Perl with Inline it works just fine plus every other Module and script I wrote previously, so everything seems ok
Thank you guys for being a lot of help, I'll go now and play with the great Inline module
Perl : awesome
C: rules
:))
here is my final Perl -V output
D:\>Perl -V
Summary of my perl5 (revision 5 version 10 subversion 1) configuration:
Platform:
osname=MSWin32, osvers=5.00, archname=MSWin32-x86-multi-thread
uname='Win32 strawberryperl 5.10.1.3 #1 Thu Jul 29 10:08:11 2010 i386'
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='gcc', ccflags =' -s -O2 -DWIN32 -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE - DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-strict-aliasing -DPERL_MSVCRT_RE ADFIX',
optimize='-s -O2',
cppflags='-DWIN32'
ccversion='', gccversion='3.4.5', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='long long', lseek size=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='g++', ldflags ='-s -L"E:\xampp\perl\lib\CORE" -L"E:\xampp\c\lib"'
libpth=E:\xampp\c\lib
libs= -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi3
2 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversio
n -lodbc32 -lodbccp32
perllibs= -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladv api32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lve
rsion -lodbc32 -lodbccp32
libc=, so=dll, useshrplib=true, libperl=libperl510.a
gnulibc_version='' Dynamic Linking:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-mdll -s -L"E:\xampp\perl\lib\CORE"
-L"E:\xampp\c \lib"'
Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV
PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
PERL_MALLOC_WRAP PL_OP_SLAB_ALLOC USE_ITHREADS
USE_LARGE_FILES USE_PERLIO USE_SITECUSTOMIZE
Locally applied patches:
ActivePerl Build 1007 [291969]
0abd0d disable non-unicode case insensitive trie matching
Built under MSWin32
Compiled at Jan 26 2010 23:15:11
@INC:
E:/xampp/perl/site/lib
E:/xampp/perl/lib