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. Advertisements

  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. Advertisements

  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. Advertisements

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:
    508
    ship261
    Nov 30, 2005
  2. harryajh

    Funny DecimalFormat problem

    harryajh, Feb 22, 2007, in forum: Java
    Replies:
    1
    Views:
    479
    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:
    324
    Kenneth Lantrip
    Jul 18, 2004
  4. Matthias Kluwe

    Funny locale problem

    Matthias Kluwe, Jul 13, 2005, in forum: C++
    Replies:
    1
    Views:
    341
    Matthias Kluwe
    Jul 14, 2005
  5. Markus Svilans

    Funny problem with virtual method

    Markus Svilans, Nov 24, 2006, in forum: C++
    Replies:
    10
    Views:
    641
    Markus Svilans
    Nov 29, 2006
  6. Hans Müller

    Funny xmlrpc / linux problem

    Hans Müller, Jun 16, 2009, in forum: Python
    Replies:
    6
    Views:
    430
    Jeff McNeil
    Jun 16, 2009
  7. Luiz Vianna

    Datagrid - Funny problem - Dinamically Adding RadioButton

    Luiz Vianna, Dec 28, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    164
    Sundararajan
    Mar 7, 2005
  8. Robin
    Replies:
    0
    Views:
    177
    Robin
    Jul 2, 2010
Loading...