tags:

views:

91

answers:

4

How to create a .so and .a file in UNIX. Do we have any standard utility for it?

+2  A: 

*.a - archive library to create it compile your sources:

gcc -c -o foo.o foo.c
gcc -c -o boo.o boo.c

ar -rsc yourlib.a foo.o boo.o

so - position independent code shared library

gcc -fPIC -shared  -soname,libfoo.so.1 -o libfoo.so.1.0 foo.c boo.c
bua
Any idea about .so file
Sachin Chourasiya
second (-fPIC) creates *.so libraries, Your sources needs to be compiled this way, no other way (I don't know other ways).
bua
+1  A: 
#create shared library
gcc -Os -fPIC -c test.c
gcc -shared  test.so test.o 


#create static library
gcc -Os -c test.c
ar rcs test.a test.o
pierr
A: 

Take a look at this Makefile I wrote when I was new to C. It clearly shows how to generate and correctly link .a and .so files from a simple demo source.

Matt Joiner
A: 

The .a is also called a static library, and the .so is also called a dynamically loaded library.

I like the Program Library HOWTO.

This HOWTO for programmers discusses how to create and use program libraries on Linux. This includes static libraries, shared libraries, and dynamically loaded libraries.

The Yo Linux tutorial is also useful.

This tutorial discusses the philosophy behind libraries and the creation and use of C/C++ library "shared components" and "plug-ins". The various technologies and methodologies used and insight to their appropriate application, is also discussed. In this tutorial, all libraries are created using the GNU Linux compiler.

Kinopiko