Click here to Skip to main content
16,012,223 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
main.c
C++
#include "stdio.h"
#include "function.h"
#include "function1.h"

void main()
{
printhello();
printhello1();
}

hello.c

C++
#include "stdio.h"
#include "function.h"
#include "function1.h"

void main()
{
printhello();
printhello1();
}

hello1.c
C++
#include "stdio.h"
#include "function1.h"


void printhello1()
{
printf("***************\n");

printf("Hello World second\n");
}

function.h

void printhello();

function1.h

C++
void printhello1();

Makefile
C++
CC=gcc
CDEBUG=-g
OBJ=hello.o hello1.o main.o

SRC=./inc
INC=./src
	
my_project : $(OBJ)
	$(CC) $(OBJ) -o my_project
	
main.o : function.h function1.h
	$(CC) -c main.c 
hello.o : function.h hello.c
	$(CC) -c hello.c 
hello1.o : function1.h hello1.c
	$(CC) -c hello1.c 

.PHONY clean:
clean : 
	rm -rf *.o

folder:Work/src/main.c,hello.c,hello1.c
folder:work/inc/function.h,function1.h

iam getting error like make: *** No rule to make target `function.h', needed by `hello.o'. Stop....can anyone help me reason for this????

[edit]Code block added, "Treat my content as plain text..." option disabled - OriginalGriff[/edit]
Posted
Updated 24-Jan-12 22:07pm
v2
Comments
renj00790 25-Jan-12 5:53am    
vpath %.c src
vpath %.h inc
CFLAG=-I inc

main : main.o hello.o hello1.o -1f1
gcc $^ -o $@
main.o : main.c function.h function1.h
gcc -c $<
hello.o : hello.c function.h
gcc -c $<
hello1.o : hello1.c function1.h
gcc -c $<


.PHONY clean:
rm -rf *.o

i imlemented like this..but got same error???

Try swapping the SRC and INC definitions over:
SRC=./inc
INC=./src
Becomes
SRC=./src
INC=./inc
 
Share this answer
 
Comments
renj00790 25-Jan-12 4:21am    
i implemented INCLUDE files in SRC ....
OriginalGriff 25-Jan-12 4:32am    
Not according to your folders list.
It is complaining that it can't find "function.h", so it assumes it is a build target and is reporting it does't know how to find it.
Try swapping them over, that may fix it.
CPallini 25-Jan-12 4:39am    
To fool the enemy?
I don't see anything in the make file that tells make where the source and include files are stored. Thus when trying to buid hello.o it cannot find the first dependency (function.h) and the make file does not contain a rule to create it.
 
Share this answer
 
vpath %.c src
vpath %.h inc
CFLAG=-I inc
main : main.o hello.o hello1.o
gcc $^ -o $@
main.o : main.c function.h function1.h
gcc -c $< $(CFLAGS)
hello.o : hello.c function.h
gcc -c $< $(CFLAGS)
hello1.o : hello1.c function1.h
gcc -c $< $(CFLAGS)
.PHONY clean:
rm -rf *.o
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900