Finding a dynamic library dependency

At a customer visit this week I was asked if the compiler libraries can be reshipped with an application.  And of course the answer is yes.  A complete list of those libraries can be found at:

/opt/SUNWspro/READMEs/runtime.libraries

This reminded me of another question about how an application can locate library dependencies when the application can be installed in a user defined location.  For example, you have an application whose dynamic library is always located relative to itself via the path ../lib, like this:

cobol% ls -laF bin prod prod/bin .
.:
total 48
drwxr-xr-x   4 bin      bin        512 Mar  6 08:15 ./
drwxrwxrwx   5 bin      bin       1024 Mar  5 10:23 ../
drwxr-xr-x   2 bin      bin        512 Mar  5 10:37 bin/
-rw-r--r--   1 bin      bin       2178 Mar  6 08:15 myapp.c
drwxr-xr-x   3 bin      bin        512 Mar  5 10:37 prod/

bin:
total 6
drwxr-xr-x   2 bin      bin        512 Mar  5 10:37 ./
drwxr-xr-x   4 bin      bin        512 Mar  6 08:15 ../
lrwxrwxrwx   1 bin      bin         20 Mar  5 10:37 myapp -> ../prod/bin/myapp

prod:
total 6
drwxr-xr-x   3 bin      bin        512 Mar  5 10:37 ./
drwxr-xr-x   4 bin      bin        512 Mar  6 08:15 ../
drwxr-xr-x   2 bin      bin        512 Mar  6 08:15 bin/
drwxr-xr-x   2 bin      bin        512 Mar  6 08:15 lib/

prod/bin:
total 4
drwxr-xr-x   2 bin      bin        512 Mar  6 08:15 ./
drwxr-xr-x   3 bin      bin        512 Mar  5 10:37 ../
-rwxr-xr-x   1 bin      bin       8972 Mar  6 08:33 myapp\*

prod/lib:
total 4
drwxr-xr-x   2 bin      bin        512 Mar  6 08:15 ./
drwxr-xr-x   3 bin      bin        512 Mar  5 10:37 ../
-rwxr-xr-x   1 bin      bin       8972 Mar  6 08:33 mylib.so\*
cobol%

The linker provides Dynamic String Tokens that can be used to when creating the application.  In this case the token is called: $ORIGIN

And would be used as follows:

% cc -o prod/bin/myapp myapp.c '-R$ORIGIN/../lib' -L prod/lib -lmylib

For details about $ORIGIN and other Dynamic String Tokens see the Linker and Libraries Guide on docs.sun.com.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Douglas is a principal software engineer working as the C compiler project lead and the Oracle Solaris Studio technical lead.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today