Linker input and output files

The linker takes object files, links them with each other and with any library files that you specify, and produces an executable output file. The executable output can be either an executable program file or a shared object.

Linker inputs:
  • Options
  • Object files (*.o)
  • Archive library files (*.a)
  • Dynamic library files (*.so)
  • Import files (*.imp)
Linker outputs:
  • Executable file (a.out by default)
  • Shared object
  • Return code

Import files: Import files are ASCII files that identify the external symbols to resolve at run time. An import file identifies the shared object that defines the imported symbols. The system loader finds and resolves those symbols. If the first line of an import file begins with #! (pound sign, exclamation point), you can specify the file on the command line as an ordinary input file. Otherwise, you must use the -bI or -bimport option to specify the import file.

Export files: Export files are ASCII files that identify external symbols that are made available for another executable object file to import. The file format of an export file is the same as the file format of an import file.

Library files: Libraries are files that have suffix .a or .so. To designate a library, you can specify an absolute or relative path name or use the -l (lowercase letter L) option in the form -lname. The last form designates file libname.a, or in dynamic mode, file libname.so, to be searched for in several directories. These search directories include directories that you specify by using -L options, and the standard library directories /usr/lib and /lib.

The environment variable LIBPATH is not used to search for libraries that you specify on the command line either explicitly (for example, libc.a) or by using the -l option (for example, -lc). You must use -Ldir options to indicate the directories to be searched for libraries that you specified with a -l option.

If you specify a shared object, or an archive file that contains a shared object, with an absolute or relative path name instead of with the -lName option, the path name is included in the import file ID string in the loader section of the output file. You can override this behavior with the -bnoipath option.

You can create library files by combining one or more files into a single archive file by using the AIX ar command.

Example: creating a sample shared library