Linker search rules

When searching for an object file (.o), archive library file (.a), or import file (.imp), the linker looks in several locations until the search is satisfied.

The linker searches these locations:

  1. The directory that you specify for the file

    If you specify a path with the file, the linker searches only that path and stops linking if the file cannot be found there.

  2. The current directory, if you did not specify a path
  3. The value of the environment variable LIBPATH, if defined

The search for files depends on several ld options. If you specify -brtl, runtime linking is enabled. When it is used in conjunction with either -bdynamic or -bshared, the search for libraries that you specify with the -l option is satisfied by the suffix .so or .a. For each directory searched, a file with the suffix .so is looked for. If that search fails, a file with the suffix .a is looked for. If neither file is found, the search continues with the next directory.

If you use libraries other than the default ones in /usr/lib, you can specify one or more -L options that point to the locations of the other libraries. You can also set the LIBPATH environment variable, which lets you specify a search path for libraries at run time.

If the linker cannot locate a file, it generates an error message and stops linking.