|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Difference between objects and shared objects
Hi there!
I'm a Unix/Solaris newbie and I have no idea what an (shared) object is. Can somebody eyplain it to me? Micha |
|
#2
|
|||
|
|||
|
This question does not have a reasonable answer. It's like asking about the difference between a "unit" and a "central processing unit". Or asking the difference between an "expression" and a "regular expresson".
I can tell you what a "shared object" is. But it's not like there are "private objects" that together with "shared objects" are called "objects". When you write a C program, you will typically call functions like printf(), getc(), etc. These reside in a large file called a "library". When you build the program, the compiler would arrange for linker to search a file called libc.a to find printf. But if you have 100 different programs running, you would have 100 copies of printf in core. That is not efficient. So you can use a shared library instead. Here one copiy of the shared library is in core. And the 100 different program can connect to it. The shared library (on a Sun) would be called libc.so or maybe libc.so.1. The "so" stands for shared object. |
|
#3
|
|||
|
|||
|
I understand it so far.
But can't I do the same with a usual object? I mean if a program can call a function from a shared object then what is the purpose of a usual object? Micha |
|
#4
|
|||
|
|||
|
*sigh*
Reread the second paragraph of my first post. Now reread it once more, but substitute "usual" where I have "private". Repeat this procedure for every other adjective. |
|
#5
|
|||
|
|||
|
I'm so sorry, that your explaination is to big for my small brain
![]() Look, if I compile a module in C++ I can get *.o and (for CC with -KPIC) *.so afaik the *.o stands for object, while the *.so stands for shared object. See what I mean? What's the difference? Micha |
|
#6
|
|||
|
|||
|
Well, contrasting object files and shared objects is kinda interesting. A .o file is the real output from a compiler.
The ln command collects .o files and assembles a runable program. It can grab .o files from a directory. Or it can get them from a library. Or it can get them from a shared object. Most other versions of unix use the term "shared library" rather than "shared object". That way you can say that a library is a collection of object files. Thanks to your question, I see where Sun got this naming convention, but I still hate it. From now on, I will use "library" to mean "library or shared object". You don't usually run ln directly. It's common to let the compiler run it for you. That way the compiler can tell ln which libraries to search. ln can collect .o files and create a .so library. ar can collect .o files and assemble a .a library. Since executable files and .so libraries are created by ln which is invisibly run by the compiler, it looks like the compiler is creating them. Most compilers make .o files (and a few make .a files then invoke an assembler to create the.o) But ln or ar create libraries. Because a library is a collection of object files, it needs some metadata, ie, a table of contents. Even if a library has only one object file, it will not be an identical copy of that object file. I suppose that every program including the kernel that tries to use a library could be extended to work with an object file as well. This would make these programs (including the kernel) larger without providing any real new value. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Difference between objects and shared objects |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|