Alien-Build icon indicating copy to clipboard operation
Alien-Build copied to clipboard

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

Open nrdvana opened this issue 2 years ago • 1 comments

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

nrdvana avatar Apr 20 '23 21:04 nrdvana

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.

plicease avatar May 09 '23 16:05 plicease