On the research computing systems at IU, how do I link to a library?
On a Unix system, such as one of the research
computing systems at Indiana University, if the library file resides in one of
the standard directories (i.e.,
/usr/local/lib), you can link to the library by using the
-l flag (lowercase L). For example, linking
-lx flag actually means the library file is
libx.so in one of the standard
If the library is not in a standard directory, use the
-L flag (uppercase L) to explicitly specify
the library file search path. For example, if the LAPACK library
resides in the
/libapps/lapack directory, use the
following to link with it:
ld usually searches in the
directories specified by the
-L flag first,
and then in the standard directories. The first match will satisfy the
search. If files with both
extensions are found in a directory, the
.so file is
For more, see the
ld man page. Also, see When compiling a C program in Unix, why do I get "ld: Unresolved:"?
Note: In some special cases, you cannot link to a
-l flags; for example, on
Solaris systems, the Sun Performance Library uses
This document was developed with support from National Science Foundation (NSF) grant OCI-1053575. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the NSF.
Last modified on September 05, 2013.