4

I know how to add to GNU ld's library search path using the -Ldir option and use it extensively. But as far as I can tell from reading the manuals of gcc and ld, there is no way to add to the end of the list of library search paths.

The -L option adds to the beginning, after which it searches the default system library paths. But I want to add a look-here-if-you-can't-find-it-anywhwere-else path. Is there any way to do that with ld?

I can imagine a hacky-crap solution that extracts all standard library dirs (using -print-search-dirs) and adds them to the list of -L search dirs in the order I desire, ahead of their implied duplicates as default search paths...

But there must be a better way...

Bryce Schober
  • 130
  • 10

2 Answers2

0

The /etc/ld.so.conf file has a system-wide list of directory paths where libraries are searched at compile-time, the newline separated order of entries of such file is honored.

After modifying that file you must run ldconfig (as root) so that the new setting becomes active.

Jaromil
  • 76
  • 5
0

I don't think you can do exactly what you want. However, what if you force all of the symbols in the libraries you're including to be weak with the following ld flag:

 -weak_library path_to_library
             This is the same as listing a file name path to a library on
             the link line except that it forces the library and all ref-
             erences to it to be marked as weak imports.

This way, if other libraries are included with stronger symbols, they'll override the symbols in look-here-if-you-can't-find-it-anywhwere-else.so. If there are no stronger symbols defined in the libraries mentioned in LD_LIBRARY_PATH, the weak symbols in look-here-if-you-can't-find-it-anywhwere-else.so will be used.

sholsapp
  • 15,542
  • 10
  • 50
  • 67