This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Problems with math.h


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)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]