Mail Archives: djgpp/1997/12/13/20:19:09
Ryan McGee wrote:
>
> I'm interested in compiling a file into a library, but I cant find a
> help file telling me how to do this. Can anyone help me?
Libraries are created for the purpose of storing object files. To this
end, the first step in creating a library is to compile your code to
objects with the '-c' parameter:
gcc -Wall -g -O2 -c foo.c bar.c baz.c
The second step is to build the library. The GNU Binutils come with a
utility called 'ar' to manage archives (libraries). The syntax to add
object files to a library is thus:
ar rvs libjunk.a foo.o bar.o baz.o
The third step is to use the library. If you place 'libjunk.a' in a
location on the LIBRARY_PATH (defined in djgpp.env), then you can link
it using the '-l' parameter like any other library:
gcc -Wall -g -O2 -o myprog.exe myprog.c -ljunk
If you want to link it from a nonstandard directory, you can use the
'-L' parameter to tell the linker where to look. The following code
tells ld to look in the current directory as well as any defined in
LIBRARY_PATH:
gcc -Wall -g -O2 -o myprog.exe myprog.c -L. -ljunk
You can, of course, specify the filename manually, causing gcc to treat
the library like any other file:
gcc -Wall -g -O2 -o myprog.exe myprog.c libjunk.a
For more information, read the docs of 'ar', and look in chapters 6 and
8 of the FAQ.
hth
--
---------------------------------------------------------------------
| John M. Aldrich | "A woman is not property, and hus- |
| aka Fighteer I | bands who think otherwise are living |
| mailto:fighteer AT cs DOT com | in a dreamworld." |
| http://www.cs.com/fighteer | - Lazarus Long |
---------------------------------------------------------------------
- Raw text -