SUMMARY: compiling error using gcc

From: Feng Qiu (
Date: Mon Jan 06 1997 - 13:10:47 CST

Thanks all for so many quick responses!

Anwser is so simple:

*Add "-lm" at the *end* of the link command line.

*I guess you haven't linked to libm.? which contains the math functions
on UNIX. Try something like

        gcc prog.o some_more_objects libraries -lm

*The "pow()" function is in "libm.a", so you need the switch "-lm" in
compile command. For example: "gcc program.c -o program -lm".

*You need to link in the math library (pow() is a math function not in
libc). Add '-lm' (without the quotes) to the command line you are
compiling with, or to the makefile.

*Try compiling with the -lm option (also making sure that a "#include
<math.h>" is in the source C file too). For example, if the input C
file is called "foo.c", the commmand is:

        gcc -o foo foo.c -lm

Then run the program by typing "foo". The -o option allows the output
file name to be set - this is more convenient than typing "a.out".

*this means you have not used the math library for linking. the command

        man pow

will show you:

exp(3M) Mathematical Library exp(3M)

     exp, expm1, log, log1p, log10, pow - exponential, logarithm,

     cc [ flag ... ] file ... -lm [ library ... ]

     #include <math.h>

so just change the gcc command line to include the -lm option with the
other libraries (if any) and all should be fine.

* Yes, that's because you must explicitly link the math library.
can do this by specifying -lm in the gcc command line. Example:

gcc -O2 -o prueba prueba.c -lm

* You need to link with the math library. To do that, add "-lm" to
gcc commandline. For example:

        gcc -lm file.c -o file

If you're building something from a Makefile, you probably want to add
"-lm" to the linker flags. To do this, put a line like:

        LDFLAGS=$(LDFLAGS) -lm

near the beginning of the Makefile.

*Function double pow(double x, double y) is in the math library.
Look if -lm is linked to the program (libm.a,,...).

*You need to tell the compiler to link with the math library. (gcc flag
The man page for pow (exp(3m)) tells you this.


Thanks To:

Casper Dik <casper@holland.Sun.COM> (DON FREELEy) (Frank Pardo)
Colin McNeill <>
rauthenberg@HHI.DE (Stefan Rauthenberg) (Maes_Eric)
Justin Zaglio <>
smckinty@sunicnc.France.Sun.COM (Steve McKinty - Sun Microsystems
Grenoble) (Syed Zaeem Hosain)
john benjamins <johnb@Soliton.COM>
Bin Wang <>
"Alfredo Sola" <>
"Scott W. Gifford" <>
"Karl E. Vogel" <>
Joe Johnson <>
Peter Asboeck <>

Orignal message:
> I have gcc2.7.2 installed under /opt/ using solaris2.5.1.
> When I compile a program, give error:
> Undefined first referenced
> symbol in file
> pow /var/tmp/cca0069x1.o
> ld: fatal: Symbol referencing errors. No output written to a.out

This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:11:42 CDT