exp function doesn't compile

This is a discussion on exp function doesn't compile within the C Programming forums, part of the General Programming Boards category; Hi, I am trying to use the exp function in my code, which is below. My file is called neural2 ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    59

    exp function doesn't compile

    Hi,

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

    Code:
    #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?

    Code:
    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
    Location
    Canada
    Posts
    8,045
    Some systems (such as yours) require you to link with the math library. For GCC, use -lm.
    Code:
    $ 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.
    dwk

    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: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    And print it using the appropriate specifier.
    Code:
    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, 08:10 AM
  3. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 07: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, 01:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21