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 :)

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().

Edited 5 Years Ago by gerard4143: n/a

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

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.

Edited 5 Years Ago by gerard4143: n/a

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

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.

This article has been dead for over six months. Start a new discussion instead.