Linking basics

Using the Linker

To invoke the Stony Brook linker, use:

sblink -exetype:xxx linkerArguments

The exetype qualifier informs sblink about the format of the input files and the format of the output executable. The default value of the linker is to link programs for the host operating system. Therefore if the development system is running under Win32 then the linker defaults to Win32. Linux is the default for Linux based systems. SunOS is the default for Solaris based systems.

All of the object files, object libraries and linker qualifiers can be presentedto the linker in any order.  The arguments are separated by spaces.

Linker qualifiers are identified by a preceding "-" character. The "/"character may also be used on non Unix platforms. Linker qualifiers are not casesensitive and you only need enter the minimum number of characters in the qualifiername that uniquely identifies the qualifier. See Linker Qualifiers.

You must include the language runtime library and operating system API objectlibraries when linking your program.

ExeType Necessary libraries
Win32 rtl32win.lib, win32api.lib
Linux rtl32lnx.lib (libc.so and likely other shared objects)
SunOS rtl32sun.lib (libc.so and likely other shared objects)

Win16

rtl16win.lib, win16api.lib

X32

rtl32dos.lib

DOS

rtl16dos.lib

Some target systems require a special object be linked first.

ExeType First object
X32 sbx32.obj
Win16 program winstart.obj
Win16 DLL libentry.obj

EXAMPLE: Linking a program

For example, to link a Win32 program named "main" with modules named"m1" and "m2", use the following command:

sblink main.obj m2.obj m2.obj \InstallDir\rtl32win.lib \InstallDir\win32api.lib -subsystem:Windows,4.00 -map:main -out:main.exe

This command creates the program "main.exe" and the map file "main.map".

For large programs, you might want to create a response file to specify the parametersto sbLink.  The response file contains the parameters to the linker.

In a response file for the Stony Brook linker, each line is processed a continuationof the command line. A response file is identified on the command line with a preceding"@" character. If you do not supply an extension for the file name andthe file name is not found then ".lnk" is an assumed file extension.

EXAMPLE: Linker response file

For example, the following response file named "linkit.lnk" could beused to link the program "main.exe" mentioned above:

-SUBSYSTEM:WINDOWS,4.00
-MAP:main
-OUT:main.exe
main.obj
m2.obj
m2.obj
\InstallDir\rtl32win.lib
\InstallDir\win32api.lib

To link this file, use the command:

sblink  @linkit.lnk