Makefile

Im doing a Makefile to include 3 files:

Weapons.cpp
Weapons.h
and assignment 10.cpp

is this correct code for the Makefile:
1
2
3
4
5
  1 assignment 10: assignment10.cpp Weapon.h Weapon.cpp
  2     g++ assignment10 assignment10.cpp Weapon.cpp
  3 
~                                                                               
~                                                   


Also, will this make so Weapon.cpp is included in assignment10.cpp like I #include"Weapon.h" in Weapon.cpp?
or How would I include Weapon.cpp in assignment.cpp?
is this correct code for the Makefile:
No, it has to do with dependency. You tell make that the file before : depends on the file(s) after.

Why do you care for a makefile. Todays ide's can handle that way better.

Also, will this make so Weapon.cpp is included in assignment10.cpp like I #include"Weapon.h" in Weapon.cpp?
No, it has nothing to do with #include statement used by the compiler (it invokes a compiler, not more)

How would I include Weapon.cpp in assignment.cpp?
You do not. The presence within the makefile/project suffice (i.e. the linker has to know which of the generated object files needs to be linked)
Last edited on
I believe we were taught this method:
1
2
3
4
5
6
7
8
project.exe: main.o weapon.o
    g++ main.o weapon.o -o project.exe

main.o:  main.cpp weapon.h
    g++ -c main.cpp

weapon.o:  weapon.cpp
    g++ -c weapon.cpp


note that those are not tabs if you try to copy/paste
Last edited on
Topic archived. No new replies allowed.