Thread: exp function doesn't compile

  1. #1
    Registered User
    Join Date
    Jun 2002

    exp function doesn't compile


    I am trying to use the exp function in my code, which is below. My file is called neural2

    #include <math.h> /* for exp */
    #include <stdio.h> /* for printf, scanf */
    #include <stdlib.h> /* for atoi */
    #include <string.h> /* for strtok */
    /* begin main */
    main(int argc, char *argv[])
    		printf("%d \t", exp(-2 * 5));	
    }  /* end main */
    The error is as follows. Why is this occurring?

    Undefined                       first referenced
     symbol                             in file
    exp                                 neural2.o
    ld: fatal: Symbol referencing errors. No output written to neural2
    Last edited by VanJay011379; 09-16-2006 at 01:59 PM.
    " . . . and I lay awake, big dreamers never sleep." - David Lee Roth

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Some systems (such as yours) require you to link with the math library. For GCC, use -lm.
    $ gcc program.c -o program -lm
    Are you sure you want to use exp()? To calculate one number to the power of another, use pow().

    Were you thinking of '\n'? '\t' prints a tab.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    And print it using the appropriate specifier.
    printf("%d \t", exp(-2 * 5));
    %d is for an int -- %e, %f, %g are for floating point.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  3. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 08:55 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Replies: 3
    Last Post: 03-04-2005, 02:46 PM