954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Information regarding own libraries...

Hi everybody. I have a doubt in one of the command which is shown below.

1. I created my own adding and multiplication funtion definitions saved in two separate files named "sum.c" and "mul.c". The function calls are present in "main.c" ofcourse.
2. I got the assembler output files by
cc -c sum.c & cc -c mul.c
3. I created my own dynamic library using the "sum.o" & "mul.o" object files by
ar rcs libDynamic.so sum.o mul.o
4. I know to use the created library to generate the "a.out" file by the command
cc main.o ./libDynamic.so


I want to know what does this below command do and why it is needed?
cc -shared -o libDynamic.so sum.o mul.o
Also, to copy this libDyamic.so into standard library folder so that i can use shortcut for this library eg: cc main.o -lDynamic, what shoud i do??

All views are accepted. thank you in advance :)

b56r1
Newbie Poster
24 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

It creates a dynamic shared library that can be loaded and unloaded when the program is running, meaning you don't have to compile/link them during the compile/link cycle. Try looking up the functions in the library dlfcn.h - dlopen(), dlclose() and dlsym().

gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
 

I think static libraries neet not be recompiled. What is the main differences between shared and dyanmically loaded (DL) libraries?

b56r1
Newbie Poster
24 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

Dynamic libraries can be linked to a running process - so the linking is considered dynamic.
Static libraries are linked to a program at compile time and don't change during execution - the linking is fixed so its static.

gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
 

Yes, but i need difference b/w SHARED libraries and DYNAMIC libraries, not with static libraries.

b56r1
Newbie Poster
24 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 
gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
 

There are a number of differences between static and dynamic (shared) libraries. I'll summarize some of the more important ones:

1. If you alter a static library and wish for your applications that use it to get the new code, you have to relink them. With shared libraries, you just need to restart them.
2. If more than one application uses a shared library, then the code that is loaded into the computer's memory is also shared, so you can potentially use less memory if you have a number of applications running simultaneously that all use the same library or libraries.
3. If you link a static library, only the functions you need are linked into your program. When you link a shared library, when the program runs, the entire contents of the shared library are loaded into memory. This can offset the memory advantage of shared libraries mentioned in #2 above.
4. If you want to distribute the binary version of a program and not have your users plunged into "dll hell", then statically link it. That way (see #1 above), all the required code bits are wired directly into the application.

rubberman
Posting Virtuoso
1,564 posts since Mar 2010
Reputation Points: 277
Solved Threads: 179
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: