当我无法在目标主机上安装模块时,如何创建可移植的 perl?

发布于 2024-07-13 13:15:46 字数 1492 浏览 6 评论 0原文

我需要在 HP unix / Solaris 主机上的 cygwin Windows 上运行我开发的 Perl 应用程序。 我不是 UNIX 机器上的超级用户,我无法触及默认的 Perl 模块位置,也无法将模块安装到默认的 Perl 模块位置。 另外,unix 安装缺少最基本的模块,我无法更改这一点。

例如,我有一个 Perl 应用程序,需要 Expect ,其中包含本机 C 编译部分。 我如何将此应用程序及其所需的依赖项推出到 unix,而无需在该机器上安装其他任何东西?

有没有办法在 Cygwin Windows 下构建整个 Perl 应用程序,然后将一个可执行文件推出到 unix 并从我的主目录运行它?


根据到目前为止的答案编辑添加:

特别感谢 brian,本地 LIB 目录解决方案似乎适用于本机 Perl,但如果 Perl 模块需要 C 组件、跨平台编译,即在 cygwin 上编译以在 Solaris 上运行,正如我担心的那样,实际上是不可能的。

但是,安装其他 Linux 是否会有帮助,即在不同版本的 Unix 之间(例如 Linux 上的 Perl 包)然后部署到 Solaris/HP 是否会更容易? 那么 lcc 之类的东西怎么样?

另外,如果有人在 Windows 上推出了一个本机 Perl 包,其中包含复杂 Perl 应用程序的所有依赖项,然后可以将其作为一个文件移动到 Unix,那么我仍然想听到更多消息? (我现在明白,如果像 Expect.pm 中那样包含本机 C 代码,它将无法工作,但是如果应用程序仅使用纯 Perl 模块呢?)

基本上,出于多种原因,我试图最大限度地减少我的时间需要花费时间登录到这些“生产”unix 主机并预先在本地执行尽可能多的操作。


添加了新的交叉编译 问题,因为我觉得我可能偏离了原来的 perl 问题太远了。


编辑 - Par 看起来对于纯 Perl 很有希望,虽然同样的交易,但它看起来并不解决原生扩展的跨平台编译问题

I need to run Perl applications I develop on cygwin Windows on HP unix / Solaris hosts. I am not a superuser on the unix machines and I can't touch the default Perl module location nor can I install modules to the default Perl module location. Also the unix installation lacks most basic modules and I can't change that.

For example, I have a Perl application that needs Expect which has native C compiled parts to it. How would I roll out this application to unix with its required dependencies without having to install anything else on that box?

Is there way to build the entire Perl application under Cygwin Windows and then just roll out one executable to unix and run it from my home directory there?


EDIT addition based on answers so far:

Thanks in particular to brian, the local LIB dir solution seems to work in case of native Perl, but in case of Perl module needing C components, cross platform compiling, ie compiling on cygwin to run on Solaris, is not really possible as I feared.

However would having an other linux installation help, i.e. would this be possible easier between different flavors of Unix like package Perl on linux and then deploy to Solaris/HP? And what about something like lcc ?

Also I'd still like to hear little more if somebody has rolled out a native Perl package on Windows that includes all dependencies for a complicated Perl app that can then be moved to unix as just one file? (I do now understand that it won't work in case native C code is included like in in Expect.pm, but what about in case of app only using pure perl modules?)

Basically for many reasons I am trying to minimize time I need to spend being logged into these "production" unix hosts and do as much as possible locally beforehand.


Added a new cross-compile question, since I felt I was maybe veering too far from the original perl question.


EDIT -- Par looks promising for pure Perl, although same deal, it doesn't look to solve the cross platform compile problem for native extensions

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

颜漓半夏 2024-07-20 13:15:46

在这种情况下,我会考虑提供一个带有自己的 Perl 的完整应用程序。 您可以选择您喜欢的任何版本和您喜欢的任何模块。 编译所有内容,将所有内容组织到一个目录中,然后将结果打包。 要部署,请复制文件并解压。 使用其他人已经注意到的有关库搜索路径等的建议。本质上,您的应用程序拥有自己的堆栈。

现在,诀窍是交叉编译。 为什么要在 Cygwin 上进行开发? 这也是目标吗? 您没有 HP/UX 或 Solaris 开发机器有什么原因吗? 您的目标是什么架构(RISC、SPARC、Intel 等)。 如果您无法获得运行这些软件的硬件,请为您的目标获取一些虚拟机并在那里进行开发。

除此之外,您可以在任何有权限的地方安装模块。 请参阅perlfaq8

In this case, I'd consider delivering a complete application complete with its own Perl. You get to choose any version you like and any modules you like. Compile everything, organize everything into a directory, then tar the result. To deploy, copy the file and untar. Use the advice that others have already noted about library search paths, etc. In essence, your application gets its own stack.

Now, the trick there is the cross compilation. Why are you developing on Cygwin? Is that a target too? Is there a reason you don't have an HP/UX or Solaris development machine? What architecture are you targeting (RISC, SPARC, Intel, etc). If you can't get hardware to run those, get some virtual machines for your targets and develop there.

Aside from that, you can install modules anywhere you have permissions. See perlfaq8:

彼岸花ソ最美的依靠 2024-07-20 13:15:46

我还没有尝试过这个特殊功能,但是 perl2exe 说它支持跨平台构建。

I haven't tried this particular feature, but perl2exe says it supports cross platform builds.

孤独岁月 2024-07-20 13:15:46

使用 Cygwin 在 Windows 上编译具有所有依赖项的 Perl 脚本并在 Solaris 上运行它是行不通的。

现在的问题是:您可以访问该 Solaris 计算机上的编译器吗? 这并不是因为您没有 root 访问权限而无法使用以下方法在主目录中编译和安装 Perl 模块:

perl Makefile.PL PREFIX=$HOME

如果您的 Solaris 系统上有可用的 CPAN,您可以通过以下方式在 CPAN shell 中设置前缀:

  1. 启动 shell perl -MCPAN -e shell;
  2. 使用 conf makepl_arg PREFIX=/path/to/your/home/directory 更改前缀

要运行脚本,您可以使用 -I $HOME 命令启动 perl -line 开关,例如:

perl -I $HOME script.pl

您的另一个选择是将其放在脚本的开头

use lib $ENV{'HOME'};

Compiling a Perl script with all its dependencies on Windows with Cygwin and running it Solaris is just not going to work.

Now the question is: do you have access to a compiler on that Solaris computer? It's not because you do not have root access that you cannot compile and install Perl modules in your home directory by using:

perl Makefile.PL PREFIX=$HOME

If you have CPAN available on your Solaris system you can set the prefix in the CPAN shell this way:

  1. start the shell perl -MCPAN -e shell;
  2. change the prefix with conf makepl_arg PREFIX=/path/to/your/home/directory

For your script to run, you can either start perl with the -I $HOME command-line switch, e.g.:

perl -I $HOME script.pl

Your other option would be to place this at the begining of your script

use lib $ENV{'HOME'};
子栖 2024-07-20 13:15:46

将环境变量 PERLLIB 设置为您的个人 Perl lib 目录或使用 Perl 的 -I 命令行开关来指示它。

如果您有权访问 HP-UX 计算机,您可以在那里编译 Expect 并将其安装在您的目录中。 但从 Windows 到 HP-UX 的交叉编译可能困难得多。 您必须构建一个 GCC 交叉编译器。

Set your environment variable PERLLIB to your personnal Perl lib directory or use the -I command line switch to Perl to indicate it.

If you have access to the HP-UX machine you can compile Expect there and install it in your directory. But cross compilation from Windows to HP-UX is probably much more difficult. You would have to build a GCC cross compiler.

土豪 2024-07-20 13:15:46

如果您的每个系统上都有一个编译器(以及配置所需的一些其他工具,例如 grep),那么您不仅应该能够编译模块,而且还应该能够构建自己的 perl 可执行文件。

If you have a compiler on each of your systems (and some other tools needed by configure like grep), you should not only be able to compile modules, but you should also be able to build your own perl executables.

美煞众生 2024-07-20 13:15:46

您需要 local::lib。 完成此操作后,纯 Perl 模块应该可以跨平台工作,但您必须在外部平台上识别并重新安装已编译的模块。 在真正的 unix 上进行初始安装,cygwin 上的 cpan 速度很慢。

You'll want local::lib. Once you've done that, the pure Perl modules should work cross platform, but you'll have to identify and reinstall the compiled modules on the foreign platform. Do the initial install on a real unix, cpan on cygwin is slow.

冷弦 2024-07-20 13:15:46

我在我的工作系统中多次遇到过这种情况。 我们有 Perl 5.8 的基本安装,但我无法添加模块。 这是我使用的解决方案:

  1. 在您的文件夹中创建一个名为“lib”的文件夹
    项目根目录(例如:
    ~/projects/MyProject/lib)
  2. 任意
    从 CPAN 下载的模块
    应该有一个 Makefile 以及
    名为“lib”的目录。 将 lib 文件夹的内容复制到新创建的 lib 文件夹中。 某些模块可能仅包含单个 .pm 文件,并且没有 lib 结构。 只需复制 .pm 文件即可。

您的代码应该执行以下操作:首先,使用已正常安装的任何模块,然后取消转换 @INC 环境变量以使用本地库:

# Declare Includes --------------------------------------------------------------------------------
use Getopt::Long;
use vars qw($VERSION);
use DirHandle;
use FileHandle;


# Force perl to use our local 'lib' directory for imported modules, this allows us to
# use modules without having to install them in th emain perl assembly. However, this
#also prevents these modules from being used in other projects.
BEGIN { unshift @INC, "lib"; }
use Error qw(:try);
use SOAP::Transport::HTTP;
#use LWP::Protocol::https;
use XML::Simple;
use XML::Writer;
use XML::Writer::String;

此方法的警告是某些 Perl 模块不使用“lib”方法或者有额外的依赖项。 如果遇到问题,请检查该模块的 Makefile.PL 并查看它正在做什么。

I've run across this several times on my work systems. We have a base install of Perl 5.8 and I don't have the ability to add modules. Here's the solution I use:

  1. Create a folder called 'lib' in your
    project root (ex:
    ~/projects/MyProject/lib)
  2. Any
    modules you download from CPAN
    should have a Makefile as well as a
    directory called "lib". Copy the contents of the lib folder into your newly created lib folder. Some modules may only contain a single .pm file, and no lib structure. Just copy the .pm file.

Your code should do the following: first, use any modules that have been installed normally, then unshift your @INC environment variable to use your local libraries:

# Declare Includes --------------------------------------------------------------------------------
use Getopt::Long;
use vars qw($VERSION);
use DirHandle;
use FileHandle;


# Force perl to use our local 'lib' directory for imported modules, this allows us to
# use modules without having to install them in th emain perl assembly. However, this
#also prevents these modules from being used in other projects.
BEGIN { unshift @INC, "lib"; }
use Error qw(:try);
use SOAP::Transport::HTTP;
#use LWP::Protocol::https;
use XML::Simple;
use XML::Writer;
use XML::Writer::String;

The caveat to this method is that some Perl modules don't use the 'lib' method or have additional dependencies. If you run into problems, examine the Makefile.PL for the module and see what it's doing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文