James [on his mailserver] wrote:

> i've written a C library (call it 'foo) and made a foo.a file using 'ar'.
> Now what do i do?
> 
> i tried copying the file into /usr/local/lib and compiling a test program
> using 'gcc -Wall -lfoo test.c -o test' and it complained about undefined
> references to all my library routines.

1. The library hast to be called libfoo.a (or libfoo.so.*) if you wish
to use the `-lfoo' syntax. Otherwise you have to specify the full path
to the library file.

2. You have to list static libraries *after* the file which uses them. 
The linker only extracts the functions which have actually been
referenced prior to the inclusion of the library. Try

        gcc -Wall test.c -lfoo -o test

instead.

> i also tried making a dynamic library (foo.so.1), copied it into
> /usr/local/lib, ran ldconfig and tried compiling it like above. This time
> ld complained it couldn't find the file -lfoo.

It has to be called libfoo.so.1.

Also, the source files for shared libraries have to be compiled with
the `-fPIC' (or `-fpic') switch, otherwise they can't be shared.

-- 
Glynn Clements <[EMAIL PROTECTED]>
  • Libraries James [on his mailserver]
    • Glynn Clements

Reply via email to