0

Here's my makefile

all: main.o fileparam.o
        g++ -g $(LIBPATH) $(LIBS)  file_parameters.o main.o -o test
main.o: main.cpp
        g++ -g -Wall $(INCPATH) main.cpp -c

fileparam.o: file_parameters.cpp file_parameters.h
        g++ -g -Wall file_parameters.cpp -c

$(LIBPATH) $(LIBS) points to the libraries to be included and $(INCPATH) points to other included files

For some reason it recompiles file_parameters.o every time I make the program, and I was wondering where I screwed up. Thanks!

Edit: It does not recompile main.o every time

mrswmmr
  • 2,081
  • 5
  • 21
  • 23

2 Answers2

2

This:

fileparam.o: file_parameters.cpp file_parameters.h
        g++ -g -Wall file_parameters.cpp -c

should be:

file_parameters.o: file_parameters.cpp file_parameters.h
        g++ -g -Wall file_parameters.cpp -c

Also, calling your output file test may cause confusion - change it to mytest.

1

Its because your target, fileparam.o, is not generated by the rules... you're generating file_parameters.o instead. make sees the target doesn't exist, so it must build it.

mah
  • 39,056
  • 9
  • 76
  • 93
  • Additionally, you might change the target "all" to "test", since that rule creates "test". If you don't do that, you'll re-link every time you run make. – mah May 27 '11 at 15:59