I'm new to the world of Makefile writing. I have a C project which I want to build using GCC and I could write fairly a very good Makefile, which calls 3 other Makefiles, present in different directory structure of the project, recursively, who will then send the respective source files to the GCC compiler. The result of this step is that I'm able to see all the (5) object files of (5) source files.
Object file names (In the order of their generation)-
Makefile1
imageprocessing.o (1)
morpho.o (2)
PivBlb.o (3)
Makefile2
main.o (4)
Makefile3
bmp.o (5)
Under the confidence of seeing all the expected object files. I now add additional rules in the Makefile3, to link all the object files, here the linker will start giving the errors section as shown below.
Not just that, the last object file (bmp.o (5)) which was getting generated before is NOT getting generated anymore, my new updates to the last makefile have caused this I guess.
Whats happening here? Any hints, please?
I'm also pasting only the contents of the last Makefile - Makefile3, where Linking rules are present, below the Errors section.
Thank you
-V
-------------------------------------
**Errors**
make[1]: Entering directory `/cygdrive/c/Vikram/Projects/LOD_IMX_Project_v1/LOD1/Algorithm'
make[1]: `all' is up to date.
make[1]: Leaving directory `/cygdrive/c/Vikram/Projects/LOD_IMX_Project_v1/LOD1/Algorithm'
make[1]: Ent开发者_如何学Pythonering directory `/cygdrive/c/Vikram/Projects/LOD_IMX_Project_v1/LOD1/exe'
make[1]: `all' is up to date.
make[1]: Leaving directory `/cygdrive/c/Vikram/Projects/LOD_IMX_Project_v1/LOD1/exe'
make[1]: Entering directory `/cygdrive/c/Vikram/Projects/LOD_IMX_Project_v1/LOD1/IO'
make[1]: Leaving directory `/cygdrive/c/Vikram/Projects/LOD_IMX_Project_v1/LOD1/IO'
make[1]: *** No rule to make target `../LOD1/Algorithm/imageprocessing.o', needed by `final'. Stop.
make: *[all] Error 2
----------------------------------------
Makefile3
CC = $(TOOLS)/gcc
HFLAG = ../IO/inc
CCFLAGS = -mcpu=$(HW)
OBJ1 = ../LOD1/Algorithm/imageprocessing.o ../LOD1/Algorithm/morpho.o ../LOD1/Algorithm/PivBlb.o
OBJ2 = ../LOD1/exe/main.o
OBJ3 = ../LOD1/IO/bmp.o
all: final
final: ../LOD1/Algorithm/imageprocessing.o ../LOD1/Algorithm/morpho.o ../LOD1/Algorithm/PivBlb.o ../LOD1/exe/main.o ../LOD1/IO/bmp.o
$(CC) -o $@ $(OBJ1) $(OBJ2) $(OBJ3)
bmp.o: src/bmp.c inc/bmp.h
$(CC) $(CCFLAGS) -I$(HFLAG) -c src/bmp.c
clean:
rm -rf *o main.o
First thing to check is that the file ../LOD1/Algorithm/imageprocessing.o
actually exists and the path is correct, as make is complaining that it cannot be found.
Are you running make in the other directories yourself? If not you should add rules like
../LOD1/Algorithm/imageprocessing.o:
$(make) -C ../LOD1/Algorithm imageprocessing.o
to your main makefile.
Also as a check you can define a last result rule to list things that Make can't find, eg
%::
-echo "Make can't find $$(pwd)$@!!!"
(this might be specific to GNU make)
It sounds as if Scott Wales's suggestion solved your problem, but I'll add a couple of other things.
- The linking rule should not be in Makefile3, since Makefile3 has no power to make the objects in Algorithm/ and exe/, it should be in the master Makefile.
- With Scott Wales's help you fixed your specific path problems (my guess is that "../LOD1/Algorithm" should have been "../Algorithm"), but in general you shouldn't hard-code paths into targets like that.
- You can eliminate some redundancy by using automatic variables like $^.
#MAIN_DIR is /cygdrive/c/Vikram/Projects/LOD_IMX_Project_v1/LOD1
# or ../LOD1, your choice
vpath %.o $(MAIN_DIR)/Algorithm:$(MAIN_DIR)/exe:$(MAIN_DIR)/IO
.PHONY: all
all: final
final: imageprocessing.o morpho.o PivBlb.o main.o bmp.o
$(CC) -o $@ $^
From your error output, it looks like Makefile3 executes in
/cygdrive/c/Vikram/Projects/LOD_IMX_Project_v1/LOD1/IO
and fails to locate
/cygdrive/c/Vikram/Projects/LOD_IMX_Project_v1/LOD1/IO/../LOD1/Algorithm/imageprocessing.o
If this is the case, then perhaps
OBJ1 = ../LOD1/Algorithm/imageprocessing.o ../LOD1/Algor..
should be changed to
OBJ1 = ../Algorithm/imageprocessing.o ../Algor
Also you should have a master Makefile that "includes" the other makefiles, rather then running them in a sequence.
精彩评论