Indiana University
University Information Technology Services
  
What are archived documents?

On Big Red, Libra, or Quarry, how do I link to a library?

On Unix systems (including Big Red, Quarry, and Libra at Indiana University), if the library file resides in one of the standard directories (i.e., /usr/lib/lib or /usr/local/lib), you can link to the library by using the  -l  flag (lowercase L). For example, linking with the -lx flag actually means the library file is libx.a or libx.so in one of the standard directories.

If the library is not in a standard directory, you must 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:

-L/libapps/lapack -llapack

The linker 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 .a and .so extensions are found in a directory, the .so file is used.

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 library using  -l  flags; for example, on Solaris systems, the Sun Performance Library uses -xlic_lib .

For more information, refer to Common Questions maintained by IU's High Performance Applications staff.

This document was developed with support from the National Science Foundation (NSF) under Grant No. 0503697 to the University of Chicago and subcontracted to Indiana University. Additional support was provided by IU through its participation in the TeraGrid, which is supported by the NSF under Grants No. 0833618, SCI451237, SCI535258, and SCI504075. 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.

This is document akqm in domains all and tgrid-all.
Last modified on April 16, 2008.
Please tell us, did you find the answer to your question?