SUMMARY: compiling error using gcc

From: Feng Qiu (fqiu@bmb-fs1.biochem.okstate.edu)
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
the
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)

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

SYNOPSIS
     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.
You
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
your
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, libm.so.x,...).

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

---------------------------------

Thanks To:

Casper Dik <casper@holland.Sun.COM>
donf@brother.com (DON FREELEy)
fpardo@tisny.com (Frank Pardo)
Colin McNeill <colin@gtl.com>
rauthenberg@HHI.DE (Stefan Rauthenberg)
emm@nl.tpd.eds.com (Maes_Eric)
Justin Zaglio <justin@columbia.edu>
smckinty@sunicnc.France.Sun.COM (Steve McKinty - Sun Microsystems
Grenoble)
szh@zcon.com (Syed Zaeem Hosain)
john benjamins <johnb@Soliton.COM>
Bin Wang <bwang@er4.eng.ohio-state.edu>
"Alfredo Sola" <asola@intelideas.com>
"Scott W. Gifford" <sgifford@tir.com>
"Karl E. Vogel" <vogelke@c17.wpafb.af.mil>
Joe Johnson <jbj@alpha.hunter1.com>
Peter Asboeck <pas@servodata.co.at>
<bleary@state.ma.us>

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