-l

Category

Linking

Pragma equivalent

None.

Purpose

Searches for the specified library file. The linker searches for libkey.so, and then libkey.a if libkey.so is not found.

Syntax

Read syntax diagramSkip visual syntax diagram
>>- -l--key----------------------------------------------------><

Defaults

The compiler default is to search only some of the compiler runtime libraries. The default configuration file specifies the default library names to search for with the -l compiler option, and the default search path for libraries with the -L compiler option.

The C and C++ runtime libraries are automatically added.

Parameters

key
The name of the library minus the lib and .a or .so characters.

Usage

You must also provide additional search path information for libraries not located in the default search path. The search path can be modified with the -L option.

The -l option is cumulative. Subsequent appearances of the -l option on the command line do not replace, but add to, the list of libraries specified by earlier occurrences of -l. Libraries are searched in the order in which they appear on the command line, so the order in which you specify libraries can affect symbol resolution in your application.

For more information, refer to the ld documentation for your operating system.

Predefined macros

None.

Examples

To compile myprogram.c and link it with library libmylibrary.so or libmylibrary.a that is found in the /usr/mylibdir directory, enter the following command. Preference is given to libmylibrary.so over libmylibrary.a.
xlc myprogram.c -lmylibrary -L/usr/mylibdir


Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us