Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm a beginner and I'm so confused of how I can create and use dynamic and static libraries? I studied different websites and searched on Google but I can't understand.

Can anyone explain here in an easy way of how to create and use dynamic and static libraries in c and static vs dynamic libraries? And also please tell me why use gcc -c and gcc -o. I know gcc is a compiler but -c and -o. What is this purpose?

share|improve this question
3  
A good, but probably too complete for you, reference is akkadia.org/drepper/dsohowto.pdf – AProgrammer Nov 27 '15 at 14:54
1  
@AProgrammer would you ming posting the link as an answer so that I can upvote it? – Dadam Nov 27 '15 at 19:05
    
@Dadam, I'm of the opinion that a link is not an answer... it would need at least to be introduced by a summary that I don't feel like writing. – AProgrammer Nov 27 '15 at 20:38
up vote 2 down vote accepted

Since you don't know what -c (compile object file) and -o (specify output file) do, I would suggest to start with a simple executable compilation. Understand what are object files and how they are put together.

Proceed with static libraries. Understand that static libraries are just several object files archived together. How they are specified to the compiler and how the compiler finds them.

Then, finally, try the dynamic ones. Understand that they are linked at runtime. That you need to specify where they are found. That they are compiled and linked a different way (have you seen -fPIC yet?). That they can depend on each other. They are powerfull beasts that can bite you easily :)

And an easy way to create static and dynamic libraries? Forget about writing them manually and use cmake. If you want to go deep, run make with VERBOSE=1, see compiler arguments and learn.

share|improve this answer

not sure where to begin to answer your question here.

if you just consult the man page for gcc

 man gcc

It will perfectly address your question about the options and usage of gcc.

For the part of dynamic and static libraries, there is very long way to walk through and there is plenty clearly understandable documentation in the internet, for example:

  http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html

is a good place to start

share|improve this answer
    
all links open in my browser but this link not working in my browser.youlinux not opening – Hameed Khan Nov 27 '15 at 14:58
    
This error come This webpage is not available ERR_CONNECTION_TIMED_OUT – Hameed Khan Nov 27 '15 at 14:59
    
it is working perfectly for me, you have internet problems, it is not yolinux that is not available. – ostendali Nov 27 '15 at 15:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.