首页 > 解决方案 > How to build Perl with PERL_IMPLICIT_CONTEXT?

问题描述

According to perlguts:

When Perl is built with PERL_IMPLICIT_CONTEXT, extensions that call any functions in the Perl API will need to pass the initial context argument somehow. The kicker is that you will need to write it in such a way that the extension still compiles when Perl hasn't been built with PERL_IMPLICIT_CONTEXT enabled.

How can I build Perl with PERL_IMPLICIT_CONTEXT? And how can I later check if an installed Perl has been compiled with PERL_IMPLICIT_CONTEXT?

标签: perl

解决方案


正如@Dada 所指出的,perl 5 的构建和安装指南中提供了有关如何使用PERL_IMPLICIT_CONTEXT. 该-A选项与要添加到 的Configure脚本一起使用。例如,要构建 5.28.0并安装在:
-DPERL_IMPLICIT_CONTEXTccflagsPERL_IMPLICIT_CONTEXT$HOME/localperl

 wget https://www.cpan.org/src/5.0/perl-5.28.0.tar.gz
 tar -xzf perl-5.28.0.tar.gz
 cd perl-5.28.0
 ./Configure -des -Dprefix=$HOME/localperl -Accflags="-DPERL_IMPLICIT_CONTEXT"
 make
 make test
 make install

或者,您可以使用perlbrew

perlbrew install perl-5.28.0 --as=5.28.0ic -Accflags="-DPERL_IMPLICIT_CONTEXT"
perlbrew switch 5.28.0ic

问题的第二部分:如何检查已安装的 Perl 是否已使用 PERL_IMPLICIT_CONTEXT 编译?正如@JGNI 所指出的,perl -V可以使用:

$ perl -V | grep PERL_IMPLICIT_CONTEXT
    config_args='-de -Dprefix=/home/hakon/perlbrew/perls/5.28.0ic -Dusedevel -Accflags=-DPERL_IMPLICIT_CONTEXT -Aeval:scriptdir=/home/hakon/perlbrew/perls/5.28.0ic/bin'
    ccflags ='-DPERL_IMPLICIT_CONTEXT -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    cppflags='-DPERL_IMPLICIT_CONTEXT -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    PERL_IMPLICIT_CONTEXT

或者,您可以使用Config模块访问 Perl 配置信息。


推荐阅读