首页 > 解决方案 > How can I use rperl with perlbrew?

问题描述

I have this simple rperl program:

#!/usr/bin/env perl

use RPerl;
use strict;
use warnings;
our $VERSION = 0.001_000;

# [[[ CRITICS ]]]
## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls)  # USER DEFAULT 1: allow numeric values & print operator
## no critic qw(RequireInterpolationOfMetachars)  # USER DEFAULT 2: allow single-quoted control characters & sigils
## no critic qw(ProhibitInterpolationOfLiterals) # USER DEFAULT 3: allow anything

print 'Hello Perl', "\n";

See Exercise 1 in Learning RPerl. I am on Ubuntu 19.04, using perlbrew with perl version 5.28.1. I installed RPerl using:

$ cpanm RPerl

Then I tried to compile the above program:

$ rperl -D p.pl
[...]
[[[ SUBCOMPILE STDERR ]]]

/bin/ld: cannot find -lperl
collect2: error: ld returned 1 exit status

ERROR ECOCOSU04, COMPILER, SUBCOMPILE: C++ compiler returned error code,
[...]

标签: perlrperl

解决方案


Apparently, rperl needs to link against libperl.so, but the perl I installed rperl with was not built with a shared library libperl.so. The solution was to install a new perl using configure option -Duseshrplib:

$ perlbrew install perl-5.30.0 --notest --noman --as=5.30.0-reloc -Duseshrplib
$ perbrew use 5.30.0-reloc
$ cpanm RPerl
$ rperl -V p.pl
[...]
$ ./p
Hello Perl

推荐阅读