When compiling a C program in Unix, why do I get "ld: Unresolved:"?
When compiling a C program in Unix, an "ld: Unresolved:" error indicates that your program uses a symbol from a library which is not being linked. To solve this problem, add the following to any flags you already use when compiling your program:-lname
name with name of the appropriate library, for
test1.c is the name of the C program, and the
library referenced is
/usr/lib/libm.a, which is an
archive (static) library. The
-l flag is passed to the
linker so it can find the needed code.
- Only the part of the library filename after
libbut before the period (
.) is used with the
-lflag. Thus, the file
/usr/lib/libm.ais called by the flag
- Also, in most C compilers the
-loption must follow the name of your source file in the C compiler command line.
-l option performs a different function than the
#include directive. When you include the header file
associated with a library by placing an
directive in the program itself, this only instructs the compiler to
include the statements from that file. It does not automatically
cause the linker to search that library when linking your program.
If you are not sure what library contains the unresolved symbols,
you can use the Unix
ar command to list the contents of a
static library. Alternatively, you can use the
to obtain a name list of either a shared object or archive library.
To search for specific routines, combine these commands with the
grep command. For example, to search the list of the
symbols in the math library for those containing
could enter any of the following:
If the library you need is not in one of the directories normally
searched by the linker, you must use the
-L flag before
-l in the compile line (linkers are position
dependent), for example:
One of the defaults of the
cc command gives the location
of the standard include directory
-I/usr/include. To see
all the defaults, use the
-v verbose flag, for example:
For more information, see the man pages on
At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?
Last modified on August 22, 2008.