C
--
Questions
--
Followers
Top 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 ....
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
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) ?
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.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
C
--
Questions
--
Followers
Top Experts
C is a general-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations. By design, C provides constructs that map efficiently to typical machine instructions, so it has found lasting use in applications that had formerly been coded in assembly language, including operating systems as well as various application software for computers ranging from supercomputers to embedded systems. It is distinct from C++ (which has its roots in C) and C#, and many later languages have borrowed directly or indirectly from C.