Skip to contentSkip to conversation

How do you add to library path?

Buildroot Grant Edwards 4 participants 7 messages Apr 26, 2012 – Apr 28, 2012

lore
Share & tools
lore
#0 lore raw

What's the right way to permanently add a directory to the search path for dynamic libraries? (Preferably at build-time, rather than at run-time.)

I've added the directory path to /etc/ld.so.conf using a post-build script. But, that file seems to be ignored at boot time (and there is no "ldconfig" to run even if I wanted to).

I suppose I could set LD_LIBRARY_PATH globally, but for performance reasons, I'd prefer that the new path went into /etc/ld.so.cache. [I'm not sure how one sets a global environment variable anyway.]

There have been several threads about this in the past, but none of them seemed to offer any answers...

Signature · 3 lines
Grant Edwards               grant.b.edwards        Yow! I want a VEGETARIAN
                                  at               BURRITO to go ... with
                              gmail.com            EXTRA MSG!!
#1 lore raw
Quoted 8 lines · Grant Edwards

What's the right way to permanently add a directory to the search path for dynamic libraries? ?(Preferably at build-time, rather than at run-time.)

I've added the directory path to /etc/ld.so.conf using a post-build script. But, that file seems to be ignored at boot time (and there is no "ldconfig" to run even if I wanted to).

Quoted 6 lines

I suppose I could set LD_LIBRARY_PATH globally, but for performance reasons, I'd prefer that the new path went into /etc/ld.so.cache. [I'm not sure how one sets a global environment variable anyway.]

There have been several threads about this in the past, but none of them seemed to offer any answers...

$ grep -A8 config\ LDSO_CACHE extra/Configs/Config.in
config LDSO_CACHE_SUPPORT
	bool "Enable library loader cache (ld.so.conf)"
	depends on HAVE_SHARED
	default y
	help
	  Enable this to make use of /etc/ld.so.conf, the shared library loader
	  cache configuration file to support for non-standard library paths.
	  After updating this file, it is necessary to run 'ldconfig' to update
	  the /etc/ld.so.cache shared library loader cache file.
$ make help | grep util
  utils			- build target utilities
  hostutils		- build host utilities (see utils)
  install_utils		- install target utilities
  install_hostutils	- install host utilities

Generally speaking, you can globally export variables for sh in e.g. /etc/profile

HTH,

#2 lore raw
In reply to Grant Edwards
Quoted 3 lines · On Thursday 26 April 2012 19:42:01 Grant Edwards wrote:

What's the right way to permanently add a directory to the search path for dynamic libraries? (Preferably at build-time, rather than at run-time.)

You could use the -rpath linker option, but that risks conflicts with
libraries installed on the host (the linker puts rpath in front of the library search path, disregarding the sysroot, so if a library with the same name exists in that path on the host, the linker will link with that one instead of the cross-compiled one).

Regards,
Arnout

Signature · 6 lines
Arnout Vandecappelle                               arnout at mind be
Senior Embedded Software Architect                 +32-16-286540
Essensium/Mind                                     http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium                BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F
#3 lore raw
Quoted 11 lines · Arnout Vandecappelle
Quoted 3 lines · On Thursday 26 April 2012 19:42:01 Grant Edwards wrote:

What's the right way to permanently add a directory to the search path for dynamic libraries? (Preferably at build-time, rather than at run-time.)

You could use the -rpath linker option, but that risks conflicts with
libraries installed on the host (the linker puts rpath in front of the library search path, disregarding the sysroot, so if a library with the same name exists in that path on the host, the linker will link with that one instead of the cross-compiled one).

At a guess (untried by myself), it might be possible to use objcopy to add/change the rpath information __after__ the build is otherwise complete.

I.E: For the case where the rpath information added is for the target's use, rather than the build host's use.

I do not know for certain if objcopy can access or change the rpath information field in an object, I have never seen or read about it being done.

Mike

Quoted 3 lines

Regards,
Arnout

#4 lore raw

Hi,

There is chpath (sp?) to change the rpath later on.
This is something completely different to turning on ld.so.cache support, though.

HTH,

On 28 Apr 2012 12:44, "Michael S. Zick" <[email protected]> wrote:

Quoted 1 line · Arnout Vandecappelle

On Thursday 26 April 2012 19:42:01 Grant Edwards...

At a guess (untried by myself), it might be possible to use objcopy to add/change the rpath information __after__ the build is otherwise complete.

I.E: For the case where the rpath information added is for the target's use, rather than the build host's use.

I do not know for certain if objcopy can access or change the rpath information field in an object, I have never seen or read about it being done.

Mike

Quoted 4 lines

Regards,
Arnout

_______________________________________________
buildroot mailing list
buildroot at busybox.net
ht...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20120428/67fca940/attachment.html>

#5 lore raw
Quoted 1 line · On Saturday 28 April 2012 13:15:05 Bernhard Reutner-Fischer wrote:

There is chpath (sp?) to change the rpath later on.

Nice one! It's called chrpath and is part of Debian [1] and Ubuntu. The upstream seems to have vanished.

There's also patchelf [2] which has a git repository.

As to objcopy: I didn't find anything in the man page...

Regards,
Arnout

[1] http://packages.debian.org/source/sid/chrpath
[2] http://nixos.org/patchelf.html

Signature · 6 lines
Arnout Vandecappelle                               arnout at mind be
Senior Embedded Software Architect                 +32-16-286540
Essensium/Mind                                     http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium                BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F
#6 lore raw
In reply to Arnout Vandecappelle
Quoted 10 lines · Arnout Vandecappelle
Quoted 3 lines · On Thursday 26 April 2012 19:42:01 Grant Edwards wrote:

What's the right way to permanently add a directory to the search path for dynamic libraries? (Preferably at build-time, rather than at run-time.)

You could use the -rpath linker option, but that risks conflicts with
libraries installed on the host (the linker puts rpath in front of the library search path, disregarding the sysroot, so if a library with the same name exists in that path on the host, the linker will link with that one instead of the cross-compiled one).

Thanks, that's an interesting option. For now I've set LD_LIBRARY_PATH. That seems sub-optimal, since the libraries are always going to be in a location that's known at build-time. I'll take a look at the rpath option (and the other related methods).

Signature · 1 line
Grant