You are not logged in.

#1 2017-02-26 22:15:46

vdelecroix
Member
Registered: 2017-02-26
Posts: 14

libperl not found by ld

Hello,

I am experiencing troubles when compiling C++ code that has to be linked with libperl (see original description on github). The point is that libperl.so (as part of the perl package) is installed in a directory that is not in the linker default list, namely /usr/lib/perl5/core_perl/CORE/libperl.so. There is a workaround that consists in using the option `-L` or setting LIBRARY_PATH. However, how a configure script is supposed to find the location of libperl.so?

On the other hand, ld.so is not configure properly and any executable linked dynamically against liberl.so will fail to execute on archlinux. A work around is to set properly LD_LIBRARY_PATH. A much better permanent way consists in creating a file /etc/ld.conf.d/perl.conf with the one line /usr/lib/perl5/core_perl/CORE/ and then run ldconfig (as root). I think (but not sure) that it is a bug in the perl package. Is the ldconfiguration the right thing to do? Should this configuration step be added to the perl package?

Thanks,
Vincent

Last edited by vdelecroix (2017-02-27 14:04:40)

Offline

#2 2017-02-27 00:04:33

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: libperl not found by ld

You didn't give a github link - you just gave a link to the forums here.

Mod note: not an Apps and DEs issue, moving to Programming & Scripting.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2017-02-27 08:07:34

vdelecroix
Member
Registered: 2017-02-26
Posts: 14

Re: libperl not found by ld

The link is fixed, thanks.

Offline

#4 2017-02-27 11:48:23

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: libperl not found by ld

There's nothing there to compile.  In the github issue you've obscured the compile command used so I have no idea what the problem actually is.  There is no makefie, and only one trivially small cpp file without a main function.  My suspicion is you are linking incorrectly.  This suspicion is confirmed in the small bits of command and output you actually put on the github issue.  But if you want a solution you need to provide the ability to replicate the problem.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2017-02-27 13:45:12

vdelecroix
Member
Registered: 2017-02-26
Posts: 14

Re: libperl not found by ld

I thought that the description was clear enough. But you can do

$ gcc any_dummy_file.c -lperl
/usr/bin/ld : ne peut trouver -lperl
collect2: erreur : ld a retourné 1 code d'état d'exécution

The compilation chain for pypolymake involves cython.

But you were definitely right: the linking against libperl seemed to be superfluous in my case. I wonder why I put it here in the first place. I used to install this package in Debian without any problem, so there may still be something wrong with the perl package in archlinux.

Offline

#6 2017-02-27 13:51:18

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: libperl not found by ld

First, please post command output in English.  Second, there is no file in your repo called "any_dummy_file.c".  Of course you are suggesting that linking with "-lperl" will not work at all regardless of the tool being compiled.  I agree.  What do you think "-lperl" is supposed to mean?  That would mean link to /usr/lib/libperl.so if there were such a thing, but there isn't.  You need to provide the library path with -L, in this case -L/usr/lib/perl5/core_perl/CORE/, before you can use -lperl.

See `man gcc`.

Of course that is all assuming you need to link to perl at all.

In short, LD is not the problem, and crazy workaround hacks are not the solution.  You just need to learn how to properly link libraries in the first place which is why I wanted to see the compiler/linker command you were using (and/or Makefile).

It seems you also need '-Wl,-rpath -Wl,/usr/lib/perl5/core_perl/CORE' which I learned from the first results of a google search for "linking to libperl.co".


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#7 2017-02-27 13:59:43

vdelecroix
Member
Registered: 2017-02-26
Posts: 14

Re: libperl not found by ld

Thanks for your answer! But it does not quite answer the following question I had: how could a script guess that libperl.so is located in /usr/lib/perl5/core_perl/CORE/?

On the other hand, any executable linked dynamically against libperl.so will fail to execute on archlinux because ld.so is not properly configured.

(note: I edited my initial post to make it clearer)

Last edited by vdelecroix (2017-02-27 14:05:06)

Offline

#8 2017-02-27 14:05:06

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: libperl not found by ld

vdelecroix wrote:

On the other hand, any executable linked dynamically against libperl.so will fail to execute on archlinux because ldconfig is not properly configured.

False.  I just compiled and linked to libperl and my executable ran just fine.

vdelecroix wrote:

Thanks for your answer which does not quite answer the following question I had: how could a script guess that libperl.so is located in /usr/lib/perl5/core_perl/CORE/?

WTF?  If that's the question you had, why isn't that the question you asked?!

The general answer would be to use pkg-config which covers any library distributed with a .pc file.  It seems perl doesn't provide a .pc file.  There are a handful of libs that have their own replacement for pkg-config, perl may be one of those.  I've not had need to link to perl libs before.  But again, just do a search for compiling/linking code to perl libs.  And don't try to write your own script, use a Makefile, or perhaps autotools if you want this distributed widely.

Big picture answer: stop trying to claim that ld is broken or misconfigured and realize you just don't know how to properly link your code.  The solution to the latter is much easier: learn to link your code properly.  You are not the first person trying to distrubute code to a range of systems - there are tools to do this properly (like pkg-config, makefiles, and autotools).  Learn to use them.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#9 2017-02-27 14:08:03

vdelecroix
Member
Registered: 2017-02-26
Posts: 14

Re: libperl not found by ld

Thanks for trying this out. Since execution worked on your computer, could you tell me if libperl.so appears in the output of

$ ldconfig -p

Offline

#10 2017-02-27 14:52:31

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: libperl not found by ld

No libperl is not in the output of ldconfig.  You are really not reading anything I write, are you.  The problem is you are linking your code incorrectly.  ld.so and ldconfig are not the problem, you compiler/linker command line are.

ldd is a useful diagnostic.  Run ldd on your binary.  Here's mine:

$ ldd ./test
        linux-vdso.so.1 (0x00007fff665fa000)
        libperl.so => /usr/lib/perl5/core_perl/CORE/libperl.so (0x00007f51f7068000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007f51f6cca000)
        libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f51f6aad000)
        libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f51f68a9000)
        libm.so.6 => /usr/lib/libm.so.6 (0x00007f51f65a5000)
        libcrypt.so.1 => /usr/lib/libcrypt.so.1 (0x00007f51f636d000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f51f7458000)

This is the same line for libperl that you will find in any functioning binary that links to it.  See, for example, urxvt:

$ ldd /usr/bin/urxvt | grep perl
        libperl.so => /usr/lib/perl5/core_perl/CORE/libperl.so (0x00007f4bba85d000)

Urxvt runs perfectly fine on arch systems, and I'm sure it would on yours as well without any LD_LIBRARY_PATH hacks.  It works because urxvt is properly linked to libperl.

If the full path to libperl.so is not present in the output of `ldd` ran on your binary, then you are linking it incorrectly.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#11 2017-02-27 15:09:36

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,560

Re: libperl not found by ld

Trilby, you're not getting it. URXVT works because they use an rpath. The fact is that libperl.so is not in the linker's default path and the OP is looking for a distro-agnostic way to find it.

Offline

#12 2017-02-27 15:11:13

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: libperl not found by ld

So the solution is then to use an rpath.  What am I not getting?  The tiny test program I compiled works just fine.

The only thing that is missing is the perl equivalent of pkg-config.  I don't know exactly what this is, but I'm sure there is a proper way to link perl programs, and I'm also sure hacking LD_LIBRARY_PATH is not it.

The OP is convinced there is a problem with ld.so and/or archlinux's configuration.  They will never find a suitable solution to that problem as that is the wrong problem.  The real problem is that their code isn't being linked properly.  They need to search for a proper distro-agnostic way to link to perl.  As I'm not experienced in perl I don't know off the top of my head how that is done (as there is no .pc file) but I'm quite sure that something like perl does have an appropriate way to be linked.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#13 2017-02-27 15:15:42

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,560

Re: libperl not found by ld

You're not getting that they've been asking for a way to find the library all along, and you've been doing nothing but antagonizing and arguing.

Offline

#14 2017-02-27 15:21:07

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: libperl not found by ld

No Scimmia, you missed the edits they've made to their posts.  They started out not sharing the code, not saying what their real question was, and insisting that ld.so was misconfigured and claiming that no programs linked to perl could run in archlinux.  One cannot get help linking a program until they accept that they need to learn how to link their program.  Insisting it is a problem with archlinux is barking up the wrong tree.

It seems my nitpicking has led them to start asking the proper questions, if they don't want this help, they can say so and I'll leave this thread alone.  But as for you coming in here all high and mighty missing all the development that has happened so far and not contributing anything at all on the subject of the thread: you can just piss off.

As to the actual problem at hand, check how other tools that link to perl are built (e.g. urxvt).  I just checked urxvt's PKGBUILD.  There is no distro-specific hack to get this to work.  Instead they (as I predicted) use autotools.  The configure script detects the perl installation and creates a Makefile with proper PERLFLAGS and PERLLIB variables for the system it is run on.

The configure script detects the installed perl libs as follows:

perl -MExtUtils::Embed -e ccopts
perl -MExtUtils::Embed -e ldopts

You may want to first detect where the perl binary is as configure does in case it is not in PATH.  But this is all assuming you want to reinvent the wheel rather than use autotools which do much more thorough checks for cross-distro/os compatibility.

It would seem perl itself (with the above flags) is the perl equivalent of pkg-config.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB