How to make a static library (.a) on Linux

How to make a static library (.a) on Linux?

asked Oct 2, 2013 by anonymous

1 Answer

 
Best answer

How to generate a library from C programs in files lib1.c and lib2.c:

$ gcc -c lib1.c lib2.c

Create a library "libmy.a" using ar:

$ ar -cvq libmy.a lib1.o lib2.o

You can also list the files in a library with ar:

$ ar -t libmy.a

You can link the library in your program (e.g. p.c):

$ gcc -o p p.c libmy.a

or

$ gcc -o p p.c -L/path/to/libmy.a/directory -lmy
answered Oct 2, 2013 by anonymous

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...