WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: How do I specify the priority for alternative libraries ?  (Read 2182 times)

Online polikuo

  • Hero Member
  • *****
  • Posts: 733
How do I specify the priority for alternative libraries ?
« on: March 18, 2021, 11:01:07 AM »
I just compiled a batch of FLTK libraries that supports Xft.

Traditionally, to deal with alternatives in the older extensions.

The approach was to replace the current libraries via the tce.installed script.

This time, I passed --libdir=/usr/local/lib/fltk-xft to configure script as a custom path.

I want to keep them both, and ideally to pick the one I need with /etc/ld.so.conf in the startup script.

What is the proper way for that ?

I tried switching order, then calling ldconfig, but it doesn't yield.

P.S. I had to use attachment cause the forum kept reporting Internal Server Error

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Re: How do I specify the priority for alternative libraries ?
« Reply #1 on: March 18, 2021, 11:50:56 AM »
Have you tried using LD_LIBRARY_PATH before your execute statement?

Online polikuo

  • Hero Member
  • *****
  • Posts: 733
Re: How do I specify the priority for alternative libraries ?
« Reply #2 on: March 18, 2021, 12:02:30 PM »
Have you tried using LD_LIBRARY_PATH before your execute statement?

I know that trick.

The thing is, I want to create an extension that co-exists with the other.

Make the change system wide by telling ldconfig or something like that.

Such that when I manually delete the newer libraries, the system would fall back to older ones.

Of course a quick reboot would do the trick, but I can't help wanting to know if there's a different approach for linux in general.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: How do I specify the priority for alternative libraries ?
« Reply #3 on: March 18, 2021, 01:42:10 PM »
ld.so.conf is correct, but according to "man ld.so", the binary's RPATH has higher priority than the ld.so cache. If the binary happens to have a RPATH for /usr/local/lib, that dir comes first.

Many binaries do add a rpath for non-standard lib dirs like /usr/local/lib, you can check with "readelf -d /path/to/bin".
The only barriers that can stop you are the ones you create yourself.

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1511
Re: How do I specify the priority for alternative libraries ?
« Reply #4 on: March 18, 2021, 02:34:18 PM »
Hi, polikuo. Using RPATH sounds like the best option. You can change a binary's RPATH after compilation using the patchelf tool.

If you don't feel like compiling patchelf, you can download it for your architecture from here:
https://packages.debian.org/buster/patchelf

This is how you'd extract the .deb package (assuming you downloaded the amd64 package):
Code: [Select]
$ ar x patchelf_0.9\+52.20180509-1_amd64.deb
$ tar -xvf data.tar.xz
The patchelf binary will be inside the usr/bin/ directory.

Then something like this would do the trick for you:
Code: [Select]
$ patchelf --set-rpath <directory> <binary>For example:
Code: [Select]
$ patchelf --set-rpath /usr/local/lib/fltk-xft coolappNow  coolapp  looks in  /usr/local/lib/fltk-xft  for libraries first, before looking in the system's default directories.
« Last Edit: March 18, 2021, 02:36:05 PM by GNUser »