Thread: Anyone knows log function??

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    3

    Anyone knows log function??

    Hello..guys..
    Thank u for the answer for previous question..

    Now..I got new question for log function..

    Code:
    #include <stdio.h>
    #include <math.h>
    
    int main(int argc, char *argv)
    {
        int n;
        ...
        ...
        Print_Round(n);
        ...
        ...
    }
    
    Print_Round(int k)
    {
        int j=1;
        while ( j < (log10(k)/log10(2)) {
             printf("Round is %d\n",j);
        }
    }
    I wrote code like that..but there is error when I compile..
    I got those message..
    Code:
    /var/tmp/ccSHNicS.o: In function `Print_Round':
    /var/tmp/ccSHNicS.o(.text+0x1f0): undefined reference to `log10'
    /var/tmp/ccSHNicS.o(.text+0x20f): undefined reference to `log10'
    collect2: ld returned 1 exit status
    anybody help me out why the error occurs??
    Last edited by bread19; 10-31-2002 at 10:18 PM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Your compiler doesn't have a 'log10' function apparently. 'log10' isn't an ANSI standard function according to this info on log10. Any function which isn't part of the ANSI standard is only around if your compiler has implemented it. IE: Not ANSI = may not be included.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    It appears you are getting an error during the link phase. You may have to link in the math library. Someone who's familiar with linux/unix may know. Maybe some switch like: -l math

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    The logarithm functions are part of the C standardlibrary and when using them, you need to include math.h. Here are a few of the logarithm functions as stated in the standard.

    7.12.6.7 The log functions

    Synopsis
    1 #include <math.h>
    double log(double x);
    float logf(float x);
    long double logl(long double x);

    Description
    2 The log functions compute the base-e (natural) logarithm of x. A domain error occurs if the argument is negative. A range error may occur if the argument is zero.

    Returns
    3 The log functions return loge x.
    >collect2: ld returned 1 exit status

    Here ld is the linker, according to the error messages, the function log10 cannot be found. Probably you have forgotten to link a required library with the program or the path-settings are wrong.
    Last edited by Shiro; 11-01-2002 at 02:06 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  3. Brand new to C need favor
    By dontknowc in forum C Programming
    Replies: 5
    Last Post: 09-21-2007, 10:08 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM