[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-gcc
Subject:    Re: Creating libraries...
From:       Kurt Wall <kwall () hoser ! dsl ! xmission ! com>
Date:       2000-03-01 17:27:53
[Download RAW message or body]

Joćo Borsoi Soares spake unto the assembled, saying:
% Hello list. I“m a begginer developer for Linux, and I would like to know
% if someone could give me a hand creating libraries. I want to create a
% shared library. When programming for Windows I used the _export keyword
% before the classes or functions. How should I do when programming for
% Linux? And what parameters should I pass to compiler?

Are you creating static or shared libraries?

To create a static library, compile your code to object form, then
use the 'ar' utility to create an archive.  For example:

$ gcc -c libfoo.c -o libfoo.o
$ ar rcs libfoo.a libfoo.o
$ nm libfoo.a

The last command will show you libfoo.a's symbol table.

Creating a shared library is a touch more complicated:

1. Compile to object code using gcc's -fPIC option.
2. Dont' use gcc's -fomit-frame-pointer option.
3. Use gcc's -shared and -soname options.
4. Use gcc's -Wl option to pass arguments to the linker, ld.
5. Link explicity against the C library.  

For example:

$ gcc -fPIC -g -c libfoo.c -o libfoo.o
$ gcc -g -shared -Wl,-soname,libfoo.so -o libfoo.so.1.0.0 libfoo.o -lc

This creates a shared library named libfoo.so.1.0.0.  Ideally, you
would want to create a couple of symlinks to it, one for the soname,
libfoo.so, and one for the "standard" library file, libfoo.so.1.

Kurt
-- 
No group of professionals meets except to conspire against the public at large.
		-- Mark Twain

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic