Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is rpath-link used in cross compilation?

I'm having trouble confirming my understanding of how rpath-link works when cross compiling with the specific tool chain I'm using (though I think this a general question that applies to cross compiling in general).

When I take a look at what flags are passed to the compiler and linker when building libraries and applications, I see the following passed to the linker:

-Wl,-rpath-link,/home/Dev/env/sys/crosscompiletoolchain/armle-v7/lib/

So this is a path being embedded into shared libraries being built for the target device on my development machine. This makes sense because I'd be doing all final linking on the development machine before deploying to device. When I finally deploy to the device though (ie. shared libs + application), won't those shared libs have a useless rpath-link?

The built libraries and applications seem to work fine on the target regardless, and if I'd have to guess I'd say its because the application has an environment provided by the device OS that has /lib/ as one of its default library search paths (rpath-link only specifies the first set of dirs to be searched). Is this correct?

like image 733
Prismatic Avatar asked Jun 21 '13 23:06

Prismatic


People also ask

What does rpath link do?

The -rpath-link option may specify a sequence of directory names either by specifying a list of names separated by colons, or by appearing multiple times. The linker uses the following search paths to locate required shared libraries.

What is rpath in Makefile?

In computing, rpath designates the run-time search path hard-coded in an executable file or library. Dynamic linking loaders use the rpath to find required libraries. Specifically, it encodes a path to shared libraries into the header of an executable (or another shared library).

What is cross compiling used for?

A cross compiler is useful to compile code for multiple platforms from one development host. Direct compilation on the target platform might be infeasible, for example on embedded systems with limited computing resources. Cross compilers are distinct from source-to-source compilers.


1 Answers

Check "Using LD, the GNU linker - Options - GNU Project Archives" (ftp.gnu.org/pub/old-gnu/Manuals/ld-2.9.1/html_node/ld_3.html):

The difference between -rpath and -rpath-link is that directories specified by -rpath options are included in the executable and used at runtime, whereas the -rpath-link option is only effective at link time.

like image 153
Zrin Avatar answered Jan 04 '23 15:01

Zrin