user1344389
user1344389

Reputation: 447

make file: header including another header C++

I have 3 files

main.cpp
a.h
b.h

main.cpp includes both a.h and b.h b.h includes a.h

could anyone explain me how should I write a make file for this?

Is this correct?

objects = main.o 
sources = main.cpp

myProj: $(objects) 
    g++ -o myProj $(objects)

main.o: a.h b.h 


$(objects): $(sources)
    g++ -c $(sources)

clean:
    rm $(objects) myProj

I dont know how to specify the dependency of b.h on a.h

Upvotes: 1

Views: 150

Answers (2)

harmonickey
harmonickey

Reputation: 1419

If you are at all any more confused on makefile concepts, I would recommend checking out this helpful tutorial.

http://www.cs.umd.edu/class/fall2002/cmsc214/Tutorial/makefile.html

Upvotes: 1

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726479

Since headers are always compiled as part of .c/.cpp file, there is no need to specify header-to-header dependency. The dependency that you have specified already is sufficient, because main.cpp will recompile when a.h and/or b.h change.

Upvotes: 2

Related Questions