开发者

Creating .so and .a in UNIX

How to create a .so and .a file in UN开发者_如何学JAVAIX. Do we have any standard utility for it?


*.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


#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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜