error while using fuction log2f()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • neha_chhatre@yahoo.co.in

    error while using fuction log2f()

    hello
    im writing a c program in ubuntu,
    im using the function log2f(float)
    float stands for a float value....
    im getting the following error


    neha@neha:~/midi$ gcc twinkle_formula .c
    twinkle_formula .c: In function 'main':
    twinkle_formula .c:129: warning: incompatible implicit declaration of
    built-in function 'log2f'
    /tmp/ccE68wDB.o: In function `main':twinkle_ formula.c:(.tex t+0x333):
    undefined reference to `log2f'
    collect2: ld returned 1 exit status


    please help me out as soon as possible
  • Vimal Aravindashan

    #2
    Re: error while using fuction log2f()

    neha_chhatre@ya hoo.co.in wrote:
    hello
    im writing a c program in ubuntu,
    Please post the code that you have, or at least the relevant parts of it.
    im using the function log2f(float)
    float stands for a float value....
    im getting the following error
    >
    >
    neha@neha:~/midi$ gcc twinkle_formula .c
    twinkle_formula .c: In function 'main':
    twinkle_formula .c:129: warning: incompatible implicit declaration of
    built-in function 'log2f'
    /tmp/ccE68wDB.o: In function `main':twinkle_ formula.c:(.tex t+0x333):
    undefined reference to `log2f'
    collect2: ld returned 1 exit status
    >
    Make sure that you have included 'math.h'


    Regards,
    Vi

    Comment

    • neha_chhatre@yahoo.co.in

      #3
      Re: error while using fuction log2f()

      On Jan 21, 3:02 pm, Vimal Aravindashan <vi...@dontspam me.plswrote:
      neha_chha...@ya hoo.co.in wrote:
      hello
      im writing a c program in ubuntu,
      >
      Please post the code that you have, or at least the relevant parts of it.
      >
      im using the function log2f(float)
      float stands for a float value....
      im getting the following error
      >
      neha@neha:~/midi$ gcc twinkle_formula .c
      twinkle_formula .c: In function 'main':
      twinkle_formula .c:129: warning: incompatible implicit declaration of
      built-in function 'log2f'
      /tmp/ccE68wDB.o: In function `main':twinkle_ formula.c:(.tex t+0x333):
      undefined reference to `log2f'
      collect2: ld returned 1 exit status
      >
      Make sure that you have included 'math.h'
      >
      Regards,
      Vi

      #include<math.h >

      #include<stdio. h>

      #include<stdlib .h>

      //#include<conio. h>





      double log10(double num);



      FILE *fp;

      unsigned char volumeon=0x60;

      unsigned char volumeoff=0x00;



      void noteoff(unsigne d char data1,unsigned long value);



      struct mthd_chunk

      {



      char id[4];

      unsigned char Length[4]; /* This will be 6 */

      /* Here are the 6 bytes */

      unsigned char Format[2];

      unsigned char NumTrack[2];

      unsigned char Division[2];

      };



      struct MTRK_CHUNK

      {

      /* Here's the 8 byte header that all chunks must have */

      char ID[4]; /* This will be 'M','T','r','k' */

      unsigned long Length; /* This will be the actual size of Data[]
      */

      };



      void WriteVarLen(uns igned long value)

      {

      unsigned long buffer;

      buffer = value & 0x7F;



      while ( (value >>= 7) )

      {

      buffer <<= 8;

      buffer |= ((value & 0x7F) | 0x80);

      }



      while (1)

      {

      putc(buffer,fp) ;

      if (buffer & 0x80)

      buffer >>= 8;

      else

      break;

      }







      }

      void noteon(unsigned char data1,unsigned long value)

      {



      unsigned char data;

      WriteVarLen(val ue);

      data=0x90;

      fwrite(&data,si zeof(unsigned char),1,fp);

      fprintf(fp,"%c" ,data1);

      fwrite(&volumeo n,sizeof(unsign ed char),1,fp);

      noteoff(data1,1 29);

      }



      void noteoff(unsigne d char data1,unsigned long value)

      {

      unsigned char data;

      WriteVarLen(val ue);

      data=0x80;

      fwrite(&data,si zeof(unsigned char),1,fp);

      fprintf(fp,"%c" ,data1);

      fwrite(&volumeo ff,sizeof(unsig ned char),1,fp);



      }



      int main()

      {

      int i;



      struct mthd_chunk mthd;

      struct MTRK_CHUNK mtrk;

      unsigned char buffer[4];

      char p;

      int p2;

      //double result,f;

      float f,f1,f2,p1;

      unsigned long value;

      unsigned char data1;



      mthd.id[0]=0x4d;

      //546864;

      mthd.id[1]=0x54;

      mthd.id[2]=0x68;

      mthd.id[3]=0x64;

      mthd.Length[0]=0x00;

      mthd.Length[1]=0x00;

      mthd.Length[2]=0x00;

      mthd.Length[3]=0x06;

      mthd.Format[0]=0x00;

      mthd.Format[1]=0x00;

      mthd.NumTrack[0]=0x00;

      mthd.NumTrack[1]=0x01;

      mthd.Division[0]=0x00;

      mthd.Division[1]=0x80;

      mtrk.ID[0]=0x4d;

      mtrk.ID[1]=0x54;

      mtrk.ID[2]=0x72;

      mtrk.ID[3]=0x6b;

      mtrk.Length=0x0 0000014;



      fp=fopen("twink le3.mid","w+");

      fwrite(mthd.id, 1, 4, fp);

      fwrite(mthd.Len gth, 1, 4, fp);

      fwrite(&mthd.Fo rmat,1,2,fp);

      fwrite(&mthd.Nu mTrack,1,2,fp);

      fwrite(&mthd.Di vision,1,2,fp);



      fwrite(mtrk.ID, 1, 4, fp);

      fwrite(&mtrk.Le ngth, sizeof(unsigned long), 1, fp);

      //result=log(f);

      for(i=0;i<8;i++ )

      {

      printf("enter value of f\n");

      scanf("%f",&f);

      f1=f/440.0;

      f2=log2f(f1);



      p1=69+12*f2;

      //printf("\n%lf\n ",p1);

      p2=(int) p1;

      //printf("\n%d\n" ,p2);

      //p=(char) p2;*/



      // p='0'+34;

      // printf("\n%c\n" ,p);

      noteon(p2,0.5);

      }



      /*noteon(57.33,0 .5); noteon(56.06,0. 5);

      noteon(62.73,0. 5);

      noteon(64.24,0. 5);

      noteon(62.17,0. 5);

      noteon(58.99,0. 5);



      noteon(56.89,0. 5);noteon(56.69 ,0.5);*/







      buffer[0]=0x00;

      buffer[1]=0xff;

      buffer[2]=0x2f;

      buffer[3]=0x00;

      fwrite(buffer, sizeof(char), 4, fp);



      fclose(fp);

      //printf("%ld",re sult);

      //getch();



      }

      Comment

      • Jensen Somers

        #4
        Re: error while using fuction log2f()

        Hello,

        neha_chhatre@ya hoo.co.in wrote:
        hello
        im writing a c program in ubuntu,
        im using the function log2f(float)
        float stands for a float value....
        im getting the following error
        >
        >
        neha@neha:~/midi$ gcc twinkle_formula .c
        twinkle_formula .c: In function 'main':
        twinkle_formula .c:129: warning: incompatible implicit declaration of
        built-in function 'log2f'
        /tmp/ccE68wDB.o: In function `main':twinkle_ formula.c:(.tex t+0x333):
        undefined reference to `log2f'
        collect2: ld returned 1 exit status
        >
        >
        please help me out as soon as possible
        You have to link against the math library:
        $ gcc -lm twinkle_formula .c

        - Jensen

        Comment

        • jacob navia

          #5
          Re: error while using fuction log2f()

          neha_chhatre@ya hoo.co.in wrote:
          hello
          im writing a c program in ubuntu,
          im using the function log2f(float)
          float stands for a float value....
          im getting the following error
          >
          >
          neha@neha:~/midi$ gcc twinkle_formula .c
          twinkle_formula .c: In function 'main':
          twinkle_formula .c:129: warning: incompatible implicit declaration of
          built-in function 'log2f'
          The compiler is telling you that you have NO PROTOTYPE
          for log2f in scope, i.e. you did not include math.h

          The wording could be clearer (for example telling you that
          there is no prototype), but in gcc jargon this is how
          you get the error message.
          /tmp/ccE68wDB.o: In function `main':twinkle_ formula.c:(.tex t+0x333):
          undefined reference to `log2f'
          collect2: ld returned 1 exit status
          >
          This means that in the compiler you are using, the C library is not
          included by default so that newcomers experience how difficult it is
          to write code in C.

          This bug is there since 1985 at least, when I started using Unix.

          You have to tell the compiler that you need the C standard library
          (maths) with the cryptic command

          -lm

          in your compilation line
          gcc twinkle_formula .c -lm
          >
          please help me out as soon as possible

          --
          jacob navia
          jacob at jacob point remcomp point fr
          logiciels/informatique

          Comment

          • neha_chhatre@yahoo.co.in

            #6
            Re: error while using fuction log2f()

            On Jan 21, 3:37 pm, jacob navia <ja...@nospam.c omwrote:
            neha_chha...@ya hoo.co.in wrote:
            hello
            im writing a c program in ubuntu,
            im using the function log2f(float)
            float stands for a float value....
            im getting the following error
            >
            neha@neha:~/midi$ gcc twinkle_formula .c
            twinkle_formula .c: In function 'main':
            twinkle_formula .c:129: warning: incompatible implicit declaration of
            built-in function 'log2f'
            >
            The compiler is telling you that you have NO PROTOTYPE
            for log2f in scope, i.e. you did not include math.h
            >
            The wording could be clearer (for example telling you that
            there is no prototype), but in gcc jargon this is how
            you get the error message.
            >
            /tmp/ccE68wDB.o: In function `main':twinkle_ formula.c:(.tex t+0x333):
            undefined reference to `log2f'
            collect2: ld returned 1 exit status
            >
            This means that in the compiler you are using, the C library is not
            included by default so that newcomers experience how difficult it is
            to write code in C.
            >
            This bug is there since 1985 at least, when I started using Unix.
            >
            You have to tell the compiler that you need the C standard library
            (maths) with the cryptic command
            >
            -lm
            >
            in your compilation line
            gcc twinkle_formula .c -lm
            >
            >
            >
            please help me out as soon as possible
            >
            --
            jacob navia
            jacob at jacob point remcomp point fr
            logiciels/informatiquehtt p://www.cs.virginia .edu/~lcc-win32


            Thanks a ton...hav been tryin a lot...thanks!!!

            Comment

            • Ravishankar S

              #7
              Re: error while using fuction log2f()


              "jacob navia" <jacob@nospam.c omwrote in message
              news:fn1sm3$gmd $1@aioe.org...
              neha_chhatre@ya hoo.co.in wrote:
              hello
              im writing a c program in ubuntu,
              im using the function log2f(float)
              float stands for a float value....
              im getting the following error


              neha@neha:~/midi$ gcc twinkle_formula .c
              twinkle_formula .c: In function 'main':
              twinkle_formula .c:129: warning: incompatible implicit declaration of
              built-in function 'log2f'
              >
              The compiler is telling you that you have NO PROTOTYPE
              for log2f in scope, i.e. you did not include math.h
              >
              The wording could be clearer (for example telling you that
              there is no prototype), but in gcc jargon this is how
              you get the error message.
              >
              /tmp/ccE68wDB.o: In function `main':twinkle_ formula.c:(.tex t+0x333):
              undefined reference to `log2f'
              collect2: ld returned 1 exit status
              >
              This means that in the compiler you are using, the C library is not
              included by default so that newcomers experience how difficult it is
              to write code in C.
              >
              This bug is there since 1985 at least, when I started using Unix.
              but this is ubuntu linux: "im writing a c program in ubuntu". the linking
              of math library with -lm is necessary, but what of this warning ? has the
              correct header files been found.

              warning: incompatible implicit declaration of built-in function 'log2f'

              On my cygwin systmem it compiles and links without comments.





              Comment

              • Richard Tobin

                #8
                Re: error while using fuction log2f()

                In article <fn27r0$pf5$1@a ioe.org>, jacob navia <jacob@nospam.o rgwrote:
                >For some weird reason, gcc has divided the C library in "math" functions
                >and not "math" function
                This is nothing to do with gcc. It's how it's been on unix since long
                before either gcc or the C standard.
                >That division is *completely* arbitrary. ALl "math" functions are
                >part of the standard C library
                The C standard didn't magically appear and people rush to implement
                it. Implementations existed first, and just because the standard
                didn't make some distinction doesn't mean that everyone had to change
                their implementations to not make it either.

                It would make more sense to simply point out that the separation of
                the maths functions is no longer useful; and indeed an increasing
                number of systems no longer make it.

                -- Richard
                --
                :wq

                Comment

                Working...