what is the meaning of the Warning message,why it occurs?

N

nick

i have 5 files,when i use make command to compile them a error occurs
"make: Warning: Infinite loop: Target `c.o' depends on itself"

when i type make an warning message occurs

cc -c b.c
cc -c a.c
make: Warning: Infinite loop: Target `c.o' depends on itself
cc -c c.c
cc b.o a.o c.o -o a


1. file :c.c
#include <stdio.h>
void print(){
printf("%d",1);
}

2. file : c.h
#ifndef t
#define t
#include <stdio.h>

void print();
#endif

3. file : b.c
#include "c.h"
void print2(){
printf("%d",2);
}

4. file : b.h
void print2();

5. file : a.c
#include "b.h"
#include "c.h"
extern int h;
int main(){
print();
print2();
return 0;

}

the makefile
a: b.o a.o c.o b.h c.h
cc b.o a.o c.o -o a
b.o: b.c b.h
cc -c b.c
c.o: c.o c.h
cc -c c.c

thanks!
 
S

Skarmander

nick said:
i have 5 files,when i use make command to compile them a error occurs
"make: Warning: Infinite loop: Target `c.o' depends on itself"
<snip>

This is not a C-specific question, you're having trouble writing makefiles.
c.o: c.o c.h

You want c.c in the dependency list, not c.o.

S.
 
G

Gordon Burditt

i have 5 files,when i use make command to compile them a error occurs
"make: Warning: Infinite loop: Target `c.o' depends on itself"

Because c.o *DOES* depend on itself.
c.o: c.o c.h

See that c.o on BOTH sides of the dependency? That's a mistake.

Gordon L. Burditt
 
J

Jaspreet

nick said:
i have 5 files,when i use make command to compile them a error occurs
"make: Warning: Infinite loop: Target `c.o' depends on itself"

when i type make an warning message occurs

cc -c b.c
cc -c a.c
make: Warning: Infinite loop: Target `c.o' depends on itself
cc -c c.c
cc b.o a.o c.o -o a

[snip.c files]
the makefile
a: b.o a.o c.o b.h c.h
cc b.o a.o c.o -o a
b.o: b.c b.h
cc -c b.c
c.o: c.o c.h

Why do you have c.o on both the sides ? Remove the one on the right and
your warning should disappear. OT here though, nothing to do with c
language.
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top