compilation problem
Results 1 to 5 of 5

Thread: compilation problem

  1. #1
    Senior Member
    Join Date
    Dec 2001
    Posts
    134

    compilation problem

    I was doing the following program in RedHat-9 Linux, but the program is not getting complied, your help is sorted.
    ------------
    #include<stdio.h>
    #include<math.h>
    int main()
    {
    double pie,theth,dis,velo=0.0;


    printf("\nEnter the angle theta: ");
    scanf("%lg",&theth);

    printf("\n Enter the angle pie: ");
    scanf("%lg",&pie);

    printf("\nEnter the velocity of the projectile: ");
    scanf("%lg",&velo);

    pie=3.1415927/180.0*pie;
    theth=3.1415927/180.0*theth;

    dis=2.0*velo*velo*cos(theth)*cos(theth)*(tan(theth)-tan(pie)/(9.81 * cos(pie)));

    printf("\nThe Distance is: %g",dis);



    return 0;
    }
    ------------------------------------------
    the following command is used to compile the program.
    -------------------------
    gcc projectile.c
    -------------------------

    it shows the following output on the screen, I do not what it means and needs to be done.
    -------------------------------------------------------------------------
    /tmp/ccC2282K.oC.text+0xbb): In function ‘main’
    : undefined reference to ‘cos’
    /tmp/ccC2282K.oC.text+0xd4): In function ‘main’
    : undefined reference to ‘cos’
    /tmp/ccC2282K.oC.text+0xed): In function ‘main’
    : undefined reference to ‘tan’
    /tmp/ccC2282K.oC.text+0x101): In function ‘main’
    : undefined reference to ‘tan’
    /tmp/ccC2282K.oC.text+0x11d): In function ‘main’
    : undefined reference to ‘cos’

    --------------------------------------------------------------------
    Thank you for your time and patience.
    U get What U pay for.

  2. #2
    AO Curmudgeon rcgreen's Avatar
    Join Date
    Nov 2001
    Posts
    2,716
    gcc -lm projectile.c

    http://lists.trolltech.com/qt-intere...ad00056-0.html

    Don't ask me what the -lm means but it works.
    I compiled it and it runs.
    I came in to the world with nothing. I still have most of it.

  3. #3
    Custom User
    Join Date
    Oct 2001
    Posts
    503
    Using the -lm option makes the linker include the math library as far as I can tell. Basically what the error messages were saying is that the compiler couldn't find the function/variable (function in this case) name for some reason. This is because for some reason you have to manually include the math library.

    Also, in case you didn't know this already, you can use the -o switch if you want the binary file's name to be different from the source file:

    Code:
    gcc test.c -o test
    or
    gcc test.c -o sflkjs
    Anyhow...that was beside the point.

    ac

  4. #4
    Senior Member
    Join Date
    Feb 2004
    Posts
    620
    I've had this problem in the past too while using the sqrt() function. I never knew about the -lm though. Thanks rcgreen

  5. #5
    Senior Member
    Join Date
    Dec 2001
    Posts
    134
    Thanks guys, it your knowledge sharing was definately of help.
    U get What U pay for.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •