Skip to content

Allow linking to versioned libperl#19

Merged
ambs merged 1 commit intoambs:masterfrom
OldManYellsAtCloud:master
Nov 10, 2025
Merged

Allow linking to versioned libperl#19
ambs merged 1 commit intoambs:masterfrom
OldManYellsAtCloud:master

Conversation

@OldManYellsAtCloud
Copy link
Copy Markdown
Contributor

When trying to link to the perlapi, the module gets the library name from $Config{libperl}, and then performs some transformations to convert the value into a linker flag.

This transformation expects an unversioned library name (e.g. libperl.so) during this transformation:
Cut off the first "lib", and remove everything after the last dot: libperl.so -> perl

This transformation doesn't work in case the library is versioned, e.g libperl.so.5.40.2. In this case the linker flag becomes perl.so.5.40, which is not a valid library name, and the linking fails.

To avoid it, this patch changes the second step of the transformation logic: instead of cutting off everything after the last dot, cut off everything after the first one.

Copy link
Copy Markdown
Owner

@ambs ambs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch.
It looks good, but... are we sure a library name will never have a dot on it?

my $libperl = $Config{libperl};
$libperl =~ s/^lib//;
$libperl =~ s/\.[^\.]*$//;
$libperl =~ s/^([^\.]*)\..*$/$1/;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the dot clearly not part of any library name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm... how about explicitly cutting off everything after the start of .so and/or .so.?

When trying to link to the perlapi, the module gets the library name
from $Config{libperl}, and then performs some transformations to
convert the value into a linker flag.

This transformation expects an unversioned library name (libperl.so) during this
transformation:
Cut off the first "lib", and remove everything after the last dot: libperl.so -> perl

This transformation doesn't work in case the library is versioned, e.g libperl.so.5.40.2.
In this case the linker flag becomes "perl.so.5.40", which is not a valid library name,
and the linking fails.

To avoid it, this patch changes the second step of the transformation logic:
cut off the ".so" at the end (if it exists), or cut off everything from the start of
".so." substring, if there is anything.

Signed-off-by: Gyorgy Sarvari <skandigraun@gmail.com>
Co-authored-by: Alberto Simões <ambs@cpan.org>
@ambs ambs merged commit 155ae78 into ambs:master Nov 10, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants