Problems with math.h
Eric Meijer
tgakem@pebbles.chem.tue.nl
Fri Jan 7 01:22:00 GMT 2000
tobias_meier@my-deja.com wrote:
: Hi all,
:
: compiling this program with the command:
:
: gcc MatheTest.c
[...]
: #include <math.h>
:
: main()
: {
: printf("Ergebnis %f \n", exp(2.3));
: printf("Ergebnis %f \n", pow(2,3));
: }
[... error:]
: /tmp/ccdP8Uys.o(.text+0xe): undefined reference to `exp'
: /tmp/ccdP8Uys.o(.text+0x37): undefined reference to `pow'
... research:
: gcc -print-search-dirs
[...]
: searching math.h I get:
: /usr/include/math.h
:
: Ok, using option -B for gcc:
:
: gcc -B /usr/include/math.h MatheTest.c
[...]
: Compiling with g++ works:
[ yes... ]
: But g++ has the same search path as gcc has !
[ yep ]
: Who knows what to do ?
You stumbled on a typical newbie problem. I must say your research and
analysis of the problem are indeed impressive compared to the average
(really, no irony here). What you need to do is read the FAQ:
http://www.faqs.org/faqs/C-faq/faq/
Most notably item 14.3, but why not read all of it? The reason that g++
does work is in a _library_ it links by default that gcc doesn't.
Header files contain only declarations, not the functions themselves.
HTH,
Eric
--
E.L. Meijer (tgakem@pebbles.chem.tue.nl)
Eindhoven Univ. of Technology
Lab. for Catalysis and Inorg. Chem. (SKA)
More information about the Gcc-help
mailing list