error while using fuction log2f()

N

neha_chhatre

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:(.text+0x333):
undefined reference to `log2f'
collect2: ld returned 1 exit status


please help me out as soon as possible
 
V

Vimal Aravindashan

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:(.text+0x333):
undefined reference to `log2f'
collect2: ld returned 1 exit status

Make sure that you have included 'math.h'


Regards,
Vi
 
N

neha_chhatre

Please post the code that you have, or at least the relevant parts of it.



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(unsigned 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(unsigned 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(value);

data=0x90;

fwrite(&data,sizeof(unsigned char),1,fp);

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

fwrite(&volumeon,sizeof(unsigned char),1,fp);

noteoff(data1,129);

}



void noteoff(unsigned char data1,unsigned long value)

{

unsigned char data;

WriteVarLen(value);

data=0x80;

fwrite(&data,sizeof(unsigned char),1,fp);

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

fwrite(&volumeoff,sizeof(unsigned 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=0x00000014;



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

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

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

fwrite(&mthd.Format,1,2,fp);

fwrite(&mthd.NumTrack,1,2,fp);

fwrite(&mthd.Division,1,2,fp);



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

fwrite(&mtrk.Length, 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",result);

//getch();



}
 
J

Jensen Somers

Hello,

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:(.text+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
 
J

jacob navia

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:(.text+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
 
N

neha_chhatre

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.


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



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

Ravishankar S

jacob navia said:
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.


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

Joachim Schmitz

jacob said:
(e-mail address removed) wrote:

This means that in the compiler you are using, the C library is not
included by default
No it does not. It means that the math functions are not part of the default
C library on that implementation.
so that newcomers experience how difficult it is
to write code in C.
It only shows that it seems difficult to read manuals :cool:
This bug is there since 1985 at least, when I started using Unix.
Don't think it's a bug, as it's documented in the man-pages for the math
functions.
You have to tell the compiler that you need the C standard library
(maths) with the cryptic command
What's crypric about that?
-lm
in your compilation line
gcc twinkle_formula.c -lm
That tells the linker to _additionally_ link the math library.

Bye. Jojo
 
J

jacob navia

Joachim said:
No it does not. It means that the math functions are not part of the default
C library on that implementation.

The function log2f is part of the standard library, as I said, and it
is specified in the C standard...

For some weird reason, gcc has divided the C library in "math" functions
and not "math" function, for instance printf, even if it uses all
maths it can it is not a "math" function.

That division is *completely* arbitrary. ALl "math" functions are
part of the standard C library
It only shows that it seems difficult to read manuals :cool:

Which manual?

To find the manual of gcc you have to install the "info"
software because the standard "man" command will warn you
"This doc should be read using "info" and is maybe
out of date".

Besides, there is NO REASON to make this stupid division of
the C library.
Don't think it's a bug, as it's documented in the man-pages for the math
functions.

No. The man pages doesn't tell you that it just tell you to
What's crypric about that?

Because the is nothing in this two letters that at first sight would
indicate that it is a math library... Unless of course that you
know that -l means library and then that the .a suffix is omitted
in that case, and that a m.a library exists somewhere that means math
library.

If the command would be
-lib:math.a
then new users would (maybe) understand that a library called "math"
and probably including mathematical functions is included.
but

-lm ???
 
R

Richard Tobin

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
 
J

Joachim Schmitz

jacob said:
The function log2f is part of the standard library, as I said, and it
is specified in the C standard...
C99, not C89
For some weird reason, gcc has divided the C library in "math"
functions and not "math" function, for instance printf, even if it
uses all maths it can it is not a "math" function.

That division is *completely* arbitrary. ALl "math" functions are
part of the standard C library


Which manual?
The one for log2f, mine does (SuSE Linux 10.0):

"Compile with -std=c99; link with -lm."
To find the manual of gcc you have to install the "info"
software because the standard "man" command will warn you
"This doc should be read using "info" and is maybe
out of date".

Besides, there is NO REASON to make this stupid division of
the C library.
Once upon a time there was a reason (size of statically linked objects)
There is no reason anymore, and most implementations don't do it that way
anymore.
Hmm, log2f is C99, that wasn't around in 85
No. The man pages doesn't tell you that it just tell you to
include <math.h>. That is all. Not a single word about having
to use -lm
Then that's a bug in the manual. Bring it up with the vendor
Because the is nothing in this two letters that at first sight would
indicate that it is a math library... Unless of course that you
know that -l means library and then that the .a suffix is omitted
in that case, and that a m.a library exists somewhere that means math
library.

If the command would be
-lib:math.a
then new users would (maybe) understand that a library called "math"
and probably including mathematical functions is included.
but

-lm ???
You won't be changing the standard syntax of compilers, the -l switch is
around since quite long (and the 'm' means look for libm.a, just
like -lsocket means to link to libsocket.a)

Bye, Jojo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top