pkgconf / pkgconf

package compiler and linker metadata toolkit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using -Wl,-rpath in relocatable pc files

madebr opened this issue · comments

Is there a way of creating .pc files that are relocatable, and also provide a sane runpath?
Curently, when using ${pcfiledir} and relative dirs, these are embedded literally in the binary.

Consider this script that builds a dummy project in /tmp/dummy and user in /tmp/dummyuser:

#!/bin/bash

set -eux

mkdir -p /tmp/dummy/lib/pkgconfig /tmp/dummy/include/dummy
echo "int dummy(void);" > /tmp/dummy/include/dummy.h
echo "int dummy(void) { return 42;}" | gcc -xc - -shared -o /tmp/dummy/lib/libdummy.so
cat >/tmp/dummy/lib/pkgconfig/dummy.pc << EOF
prefix=\${pcfiledir}/../..
includedir=\${prefix}/include
libdir=\${prefix}/lib

Name: dummy
Description: Dummy library
Version: 0.1 
Conflicts:
Cflags: -I\${includedir}/dummy -I\${includedir} 
Libs: -L\${libdir} -Wl,-rpath,\${libdir} -ldummy 
Libs.private: -lm -pthread
EOF

cat << EOF | gcc -xc - -o /tmp/dummyuser $(PKG_CONFIG_PATH=/tmp/dummy/lib/pkgconfig pkgconf dummy --libs --cflags)
#include <dummy.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
  printf("%d\n", dummy());
  return 0;
}
EOF

objdump -x /tmp/dummyuser  | grep 'R.*PATH'

With pkgconf 1.8.0, the output of objdump -x /tmp/dummyuser | grep 'R.*PATH' is

  RUNPATH              /tmp/dummy/lib/pkgconfig/../../lib

Imho, pkgconf should provide a way to collapse these paths to: /tmp/dummy/lib

pkgconf does not have any way of knowing what fragment is a path and what fragment is not. Therefore, it cannot call realpath(3) for you.