468,512 Members | 1,354 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

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:(.text+0x333):
undefined reference to `log2f'
collect2: ld returned 1 exit status
please help me out as soon as possible
Jan 21 '08 #1
7 6179
ne**********@yahoo.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:(.text+0x333):
undefined reference to `log2f'
collect2: ld returned 1 exit status
Make sure that you have included 'math.h'
Regards,
Vi
Jan 21 '08 #2
On Jan 21, 3:02 pm, Vimal Aravindashan <vi...@dontspamme.plswrote:
neha_chha...@yahoo.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:(.text+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(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();

}

Jan 21 '08 #3
Hello,

ne**********@yahoo.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:(.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
Jan 21 '08 #4
ne**********@yahoo.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:(.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
>
please help me out as soon as possible

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Jan 21 '08 #5
On Jan 21, 3:37 pm, jacob navia <ja...@nospam.comwrote:
neha_chha...@yahoo.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:(.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
please help me out as soon as possible

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatiquehttp://www.cs.virginia.edu/~lcc-win32


Thanks a ton...hav been tryin a lot...thanks!!!
Jan 21 '08 #6

"jacob navia" <ja***@nospam.comwrote in message
news:fn**********@aioe.org...
ne**********@yahoo.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:(.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.
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.

Jan 21 '08 #7
In article <fn**********@aioe.org>, jacob navia <ja***@nospam.orgwrote:
>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
Jan 21 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by mike | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.