views:

334

answers:

3

Hi Guys, 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]: Entering 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
+1  A: 

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)

Scott Wales
Hi Scott Wales, your suggestion regarding *last result rule* was very useful, with that I could fix the path problems, I'm now able to build the project and my final object file is getting generated. Now I just have to see how well it will work!!! Thanks a ton for such a quick reply!!!
vikramtheone
A: 

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.

Ivo Bosticky
Hi Ivo, I made use of Scott's suggestion regarding last result rule. It was very useful and with that I could fix the path problems, I'm now able to build the project and my final object file is getting generated. Now I just have to see how well it will work!!! Thanks a ton for such a quick reply!!!
vikramtheone
A: 
Beta
Dear Beta, thanks for you reply, I'm overwhelmed by the support I got for my problem, stackoverflow community is really alive and very helpful :)I will take your automatic variables suggestion into account, I'm reading the gnu make manual carefully from the beginning now.One best part about makefiles is that it gives the programmer an insight into whats happening during the building process of a project. Writing these files may take time, but its time worth spending, worthier than spending time and money on costly IDEs.
vikramtheone
Dear Beta, I'm having issues during the linking process of a c project. I have submitted it as a new question can you please suggest me how to deal with this problem? The link for the question is here -"http://stackoverflow.com/questions/2669082/more-gcc-link-time-issues-undefined-reference-to-main"
vikramtheone
@vikramtheone: I'd like to help, but that seems to be a problem of assembler language, which I know almost nothing about. I can only suggest that you try a simpler problem first: compile and run an assembler program by itself, *then* try linking it with HelloWorld.c.
Beta