Avatar of expertblr
expertblr
 asked on

when the soname will be created ?

Hi experts,

      I was trying to get more information on the shared objets  in linux and digged in more ending up with couple of questions :

For example :

Lets say I am creating a shared object  say, libfoo.so .  The gcc option to create the shared object is as below :

$gcc -shared -Wl,-soname,libfoo.so.1 -o libfoo.so.1.0 *.o

Here we are passing the shared object name libfoo.so.1 to the gcc compiler . I know that ldconfig will create the symbolic link for the -soname ....

my question is :

+ how does the ldconfig know to create the symbolic link say  libfoo.so.1 --> libfoo.so.1.0?
+ will the information to create the symbolic link is stored in the libfoo.so.1.0 library? so , when you run the ldconfig it knows that the symbolic link to be created for libfoo.so.1  soname ?


Please explain me in detail. Please do not refer any URL.. I've already done lot of google work ....



C

Avatar of undefined
Last Comment
Infinity08

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Infinity08

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ravenpl

the soname is included in the libfoo.so.1.0 file.
expertblr

ASKER
Thank you experts for your quick response....

Now , I have the following questions:

(i) what if I do not compile the object file wihtout the -soname option ? Then how does the ldconfig creates the symbolic link if the soname informaiton is not in the library header ?

   For ex :

           $gcc -shared -Wl -o libfoo.so.1.0 *.o

     Is this also a valid way for creating a shared object ?
     Is it necessary to have the -soname option while creating a shared library ?

(ii) Secondly, I have one more Question :

      + When you compile a program say for ex : hello.c and create an executable called hello. When you do an ldd on that  excutable we see the below :
 
          [abc@sk]$gcc hello.c -o hello

          [abc@sk]$ ldd hello
                         libc.so.6 => /lib/tls/libc.so.6 (0x00723000)
                         /lib/ld-linux.so.2 (0x00706000)

    Now, how does my compiler (gcc) know to make this executable(hello) depenedent on program loader (/lib/ld-linux.so.2) and the C library (libc.so.6)  ?

     
SOLUTION
ravenpl

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Infinity08

>> Now, how does my compiler (gcc) know to make this executable(hello) depenedent on program loader (/lib/ld-linux.so.2) and the C library (libc.so.6)  ?

That will always be the case - both are needed :

1) ld-linux is needed to load all other libraries
2) libc is the C library


>>            $gcc -shared -Wl -o libfoo.so.1.0 *.o

A shared object without soname is not properly created. Having the soname is quite important for versioning.
Ie. it's recommended to always put one to avoid all kinds of problems.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck