Like Tree2Likes
  • 1 Post By Salem
  • 1 Post By rags_to_riches

Cannot resolve a compile error with GCC compiler in Fedora

This is a discussion on Cannot resolve a compile error with GCC compiler in Fedora within the Linux Programming forums, part of the Platform Specific Boards category; Hi guys I have been trying to get this code running using GCC compiler in Fedora . I get an ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Location
    Johannesburg, South Africa
    Posts
    3

    Cannot resolve a compile error with GCC compiler in Fedora

    Hi guys

    I have been trying to get this code running using GCC compiler in Fedora . I get an error while compiling which I am not able to resolve. Can someone help me out to fix this error?

    Code:
    //This program calculates the cosine of different angles.
    
    #include<stdio.h>
    #include<math.h>
    
    #define PI 3.1416
    #define MAX 180
    
    main()
            {
             int angle;
             float x;
             float y;
             angle=0;
             printf("Angle  Cos(angle)\n\n");
    
             while(angle<=MAX)
                  { x=(PI/MAX)*angle;
                    y=cos(x);
                    printf("%15d    %13.4f\n",angle,y);
                    angle=angle+10;
                  }
            }
    [anishjp@anish C_programs]$ gcc cosine_function.c -o cosine_function
    /tmp/ccITJ2Tu.o: In function `main':
    cosine_function.c: (.text+0x37): undefined reference to `cos'
    collect2: ld returned 1 exit status

    Any help would be much appreciated!

    Regards,
    Anish

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    You need to link with the math library

    gcc cosine_function.c -o cosine_function -lm
    anishjp likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,651
    Also, for future reference, that's not really a compiler error, it's a linker error. You might want to read this.
    anishjp likes this.

  4. #4
    Registered User
    Join Date
    Sep 2010
    Location
    Johannesburg, South Africa
    Posts
    3
    Thanks very much for helping me, I appreciate it much!

  5. #5
    Registered User
    Join Date
    Sep 2010
    Location
    Johannesburg, South Africa
    Posts
    3

    Thumbs up

    Quote Originally Posted by Salem View Post
    You need to link with the math library

    gcc cosine_function.c -o cosine_function -lm
    It worked!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to resolve this error in c++?
    By hr1212s in forum C++ Programming
    Replies: 4
    Last Post: 05-11-2010, 02:47 AM
  2. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 03:35 PM
  3. Can't resolve linker error!!!!
    By benshums in forum C++ Programming
    Replies: 3
    Last Post: 01-01-2008, 01:48 PM
  4. Replies: 3
    Last Post: 06-22-2005, 07:27 AM
  5. Resolve error in Windows Macro?
    By Adock in forum C Programming
    Replies: 2
    Last Post: 03-19-2002, 07:41 PM

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