PerlAlien / Alien-Build

Build external dependencies for use in CPAN
16 stars 25 forks source link

Unit tests rewrite libs "-L" to build dir, but not "-Wl,-rpath" #395

Open nrdvana opened 1 year ago

nrdvana commented 1 year ago

After the Gather stage of an Alien module, the Alien module contains strings in ->cflags and ->libs that point to the final install path. But, when Test::Alien is used, those paths are magically rewritten to the equivalent path inside the staging directory.

However, linker rpath instructions in the libs string do not get rewritten, and still point to the final install directory, resulting in a linker command like:

cc -shared -o $staging/tmp/FooTest.so -L$stage/lib -Wl,rpath,$prefix/lib $staging/tmp/fooTest.o -lfoo

The runtime linker then finds the library at $prefix/lib (or doesn't find it, on the first install of the module) and the test fails (or gives a false result).

I searched the code a while but couldn't determine where the rewrite from ${prefix} to ${stage} was occurring. It just needs to apply to -Wl,rpath in addition to -L

plicease commented 1 year ago

Can you try using Alien::Role::Dino (if you haven't already)? That has platform specific code for handling dynamic libraries, including rpath on the platforms where it is known to work.