Static libraries

The linker command archive will specify that an archive (i.e. a static library) is to be generated. The archive command is available in both command line and interactive mode.

Object files to be placed into the archive are specified using the addobj command. This informs the linker that the object specified is not to be included in the normal link process but is to be placed in the archive. Archives themselves may be added to the archive. In this way, objects may be added to already existing archives. You can also give the addobj command a listfile name preceded by @ that contains a list of files that you wish to be included.

The following example constructs an archive named NEWLIB.LIB which contains the object files FILE1.OBJ, FILE2.OBJ together with all the object files contained within LIBFILE.LIB. This results in two more object files being added to LIBFILE.LIB. Note how the file command is used to terminate the linker session and initiate building the archive.

slink
$ archive newlib.lib
$ addobj file1.obj
$ addobj file2.obj
$ addobj libfile.lib
$ file

or

slink
$ archive newlib.lib
$ addobj @listfile
$ file

where listfile contains the following text lines

file1.obj
file2.obj
libfile.lib

the command line form of this command would be:

slink -archive:newlib.lib -addobj:file1.obj
  -addobj:file2.obj -addobj:libfile.lib

or

slink -archive:newlib.lib -addobj:@listfile

Note that the load and addobj commands may be used with wildcards. For example,

addobj *.obj

A static library can then be used when creating executables and/or DLLs. For example, if a main program in main.obj calls a routine in the above file1.obj we could use

slink
$ lo main.obj
$ lo newlib.lib
$ file

and only the relevant objects will be loaded into the executable called main.exe.

 

 

 

Basket
Empty
 
Copyright © 1999-2024 Silverfrost Limited