1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

what does this error mean ?

Discussion in 'C' started by raurava, Jul 20, 2007.

  1. raurava

    raurava New Member

    Joined:
    Jul 20, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hello all ,
    I am new to C programming and trying to learn by working some online tutorials.
    I am working on a linux OS ( Ubuntu ) .

    so the program is to calculate a table of sine values and I typed in the code pretty much the way it was show in the tutorial, the code is shown below:

    Code:
    				/* Written: Winter 1995	*/
    #include < stdio.h>
    #include < math.h>
    
    void main()
    {
        int    angle_degree;
        double angle_radian, pi, value;
    
    					/* Print a header */
        printf ("\nCompute a table of the sine function\n\n");
    
    					/* obtain pi once for all */
    					/* or just use pi = M_PI, where
    					   M_PI is defined in math.h 	*/
        pi = 4.0*atan(1.0);
        printf ( " Value of PI = %f \n\n", pi );
    
        printf ( " angle     Sine \n" );
    
        angle_degree=0;			/* initial angle value 		 */
    					/* scan over angle 		 */
    
        while (  angle_degree <= 360 )	/* loop until angle_degree > 360 */
        {
           angle_radian = pi * angle_degree/180.0 ;
           value = sin(angle_radian);
           printf ( " %3d      %f \n ", angle_degree, value );
    
           angle_degree = angle_degree + 10; /* increment the loop index	 */
        }
    }
    When I try to complile the program by typing

    $ gcc program_name.c

    I get the following error :

    /tmp/cciKZE0g.o: In function `main':
    sine.c:(.text+0x58): undefined reference to `sin'
    collect2: ld returned 1 exit status


    what does this mean ?? what should I do ? can any one help ?

    thanks ,
    raurava
     
    Last edited by a moderator: Jul 20, 2007
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Have proper code blocks when you post code snippets in the posts.
     
  4. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    In C, which you are using, sin takes a double as an argument, not a float. Use sinf for floats. In C++, the functions are overloaded, so will work. Refer to your documentation for the functions you use.
     

Share This Page