Thread: math problem

  1. #1
    Registered User unixOZ's Avatar
    Join Date
    Feb 2002
    Posts
    91

    Question math problem

    Im writting a math program to calculate the area below a curve. Everything seems to be fine only that in the following funcion:

    float y(float x) {
    float y;
    /* 1
    y = --------
    exp(x^2)
    */
    /* y = 1 / fabs(exp(x*x));*/
    y= 1/fabs(exp(x*x));
    return y;
    }

    I get this error when I compile it (gcc 2.95.3) on linux 2.4.18:
    /tmp/ccvlcwTt.o: In function `y':
    /tmp/ccvlcwTt.o(.text+0x5e): undefined reference to `exp'

    Thanks for your help

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Did you: #include <math.h>
    I presume you're trying for this function.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by Hammer
    Did you: #include <math.h>
    I presume you're trying for this function.
    the error is in the linker phase, which means its not a problem that can be fixed by #including a .h; you need to link against the math library.
    hello, internet!

  4. #4
    Registered User unixOZ's Avatar
    Join Date
    Feb 2002
    Posts
    91

    Talking

    Yes, I included math.h, otherwise I would get another kind of error when compiling

  5. #5
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    It's a problem with the linking phase, as told by moi. Compile your program like:
    cc file.c -lm
    where -lm tells the compiler to look up the Maths Library too for functions, in your case, which is the exp() function to be looked for.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Help!!c problem in math
    By feelsunny in forum Tech Board
    Replies: 2
    Last Post: 10-06-2007, 03:35 AM
  3. math problem
    By Chaplin27 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 06-09-2005, 02:37 PM
  4. Math Problem....
    By NANO in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 11-11-2002, 04:37 AM
  5. Little math problem
    By Thantos in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-27-2001, 07:44 PM