funny problem in C program !

Discussion in 'C Programming' started by Suri, Nov 3, 2003.

  1. Suri

    Suri Guest

    hi im trying to run this simple program. any help shall be appreciated
    ..pls see error message.

    #include <math.h>
    #include <stdio.h>
    #include <stdlib.h>
    int main()
    {
    double pic;
    pic= 4.0 * atan(1.0);
    printf("pi is = %f \n",pic);
    }
    error when i try to compile ...

    [harshit@localhost ~]$ gcc harshit.c
    /tmp/ccRf4QzM.o(.text+0x1b): In function `main':
    : undefined reference to `atan'
    collect2: ld returned 1 exit status
     
    Suri, Nov 3, 2003
    #1
    1. Advertising

  2. Suri

    Morris Dovey Guest

    Suri wrote:
    > hi im trying to run this simple program. any help shall be appreciated
    > ..pls see error message.
    >
    > #include <math.h>
    > #include <stdio.h>
    > #include <stdlib.h>
    > int main()
    > {
    > double pic;
    > pic= 4.0 * atan(1.0);
    > printf("pi is = %f \n",pic);
    > }
    > error when i try to compile ...
    >
    > [harshit@localhost ~]$ gcc harshit.c
    > /tmp/ccRf4QzM.o(.text+0x1b): In function `main':
    > : undefined reference to `atan'
    > collect2: ld returned 1 exit status

    ^^^^^^^^^^^^^^^^^^^^^^^^^

    Suri...

    Not a compile problem. ld can't resolve atan() - try:

    gcc -lm harshit.c

    so that ld will know to search the math library.

    --> See FAQ: http://www.eskimo.com/~scs/C-faq/q14.3.html

    --
    Morris Dovey
    West Des Moines, Iowa USA
    C links at http://www.iedu.com/c
    Read my lips: The apple doesn't fall very far from the tree.
     
    Morris Dovey, Nov 3, 2003
    #2
    1. Advertising

  3. Suri

    Ben Pfaff Guest

    Suri <> writes:

    > Subject: funny problem in C program !


    Yeah, it's so funny there's a FAQ for it. Please read the FAQ.
     
    Ben Pfaff, Nov 3, 2003
    #3
  4. Suri wrote:
    > hi im trying to run this simple program. any help shall be appreciated
    > .pls see error message.



    I can see 2 C-related problems :

    > #include <math.h>
    > #include <stdio.h>
    > #include <stdlib.h>
    > int main()


    should be int main(void) or int main(int argc, char **argv)

    > {
    > double pic;
    > pic= 4.0 * atan(1.0);
    > printf("pi is = %f \n",pic);


    main must return an int. Default is EXIT_SUCCESS (defined in stdlib.h).

    > }
    > error when i try to compile ...


    The compiler should at least warn you that it reaches the end of a
    non-void function. If it doesn't, RTM and learn how to raise warning level.

    <ot> for gcc, -Wall -ansi -pedantic should be a good start </ot>

    > [harshit@localhost ~]$ gcc harshit.c
    > /tmp/ccRf4QzM.o(.text+0x1b): In function `main':
    > : undefined reference to `atan'
    > collect2: ld returned 1 exit status


    This is not a problem with the C language, it's a problem with your
    linker. And it's a FAQ. RTF !-)

    Bruno
     
    Bruno Desthuilliers, Nov 3, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vishal

    Funny Problem with system.web.mail

    vishal, Nov 29, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    445
    ship261
    Nov 30, 2005
  2. harryajh

    Funny DecimalFormat problem

    harryajh, Feb 22, 2007, in forum: Java
    Replies:
    1
    Views:
    404
    Ingo R. Homann
    Feb 22, 2007
  3. Kenneth Lantrip

    A little funny program I stumbled upon

    Kenneth Lantrip, Jul 18, 2004, in forum: C Programming
    Replies:
    0
    Views:
    284
    Kenneth Lantrip
    Jul 18, 2004
  4. Matthias Kluwe

    Funny locale problem

    Matthias Kluwe, Jul 13, 2005, in forum: C++
    Replies:
    1
    Views:
    279
    Matthias Kluwe
    Jul 14, 2005
  5. Robin
    Replies:
    0
    Views:
    125
    Robin
    Jul 2, 2010
Loading...

Share This Page