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
will show you:
exp(3M) Mathematical Library exp(3M)
exp, expm1, log, log1p, log10, pow - exponential, logarithm,
cc [ flag ... ] file ... -lm [ library ... ]
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:
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, libm.so.x,...).
*You need to tell the compiler to link with the math library. (gcc flag
The man page for pow (exp(3m)) tells you this.
Casper Dik <casper@holland.Sun.COM>
email@example.com (DON FREELEy)
firstname.lastname@example.org (Frank Pardo)
Colin McNeill <email@example.com>
rauthenberg@HHI.DE (Stefan Rauthenberg)
Justin Zaglio <firstname.lastname@example.org>
smckinty@sunicnc.France.Sun.COM (Steve McKinty - Sun Microsystems
email@example.com (Syed Zaeem Hosain)
john benjamins <johnb@Soliton.COM>
Bin Wang <firstname.lastname@example.org>
"Alfredo Sola" <email@example.com>
"Scott W. Gifford" <firstname.lastname@example.org>
"Karl E. Vogel" <email@example.com>
Joe Johnson <firstname.lastname@example.org>
Peter Asboeck <email@example.com>
> 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