c++ - Questions about my simple Makefile -
c++ - Questions about my simple Makefile -
below re-create of makefile. have couple of questions regarding project here
cxx = g++ cxxflags = -wall -g test: car.o student.o house.o main.o $(cxx) $(cxxflags) -o test main.o car.o student.o house.o main.o: student.h house.h main.cpp $(cxx) $(cxxflags) -c main.cpp car.o: car.h student.o: student.h car.h house.o: house.h clean: rm -rf main.o car.o student.o house.o test now here questions:
question 1: little confused regarding implicit makefile rules. why makefile work fine if replace
main.o: student.h house.h main.cpp with after doing clean
main.o: main.cpp could please clarify .
question 2: matter if order of dependency of test target changes (i tried few , doesnt). confirmation expert help.
test: car.o student.o house.o main.o question 3: happens when dependency header files have no commands under them such this
student.o: student.h car.h update : after running create -p part of got
house.o: house.cpp house.h # implicit rule search has been done. # implicit/static pattern stem: `house' # lastly modified 2014-10-24 01:28:16.992760877 # file has been updated. # updated. # automatic # @ := house.o # automatic # % := # automatic # * := house # automatic # + := house.cpp house.h # automatic # | := # automatic # < := house.cpp # automatic # ^ := house.cpp house.h # automatic # ? := house.cpp house.h # variable set hash-table stats: # load=8/32=25%, rehash=0, collisions=2/20=10% # recipe execute (built-in): $(compile.cpp) $(output_option) $< i confused means
you deleted previous question matter; though weren't satisfied outcome, experience have been useful stackoverflow user. please consider taking question online.
question 1: makefile works fine because dependences have not been updated. remember makefile serves initial build subsequent rebuilds, speeding latter because looks @ files have changed. in example, expressed main.o depends on couple header files. removed both dependencies. in software development cycle, header files changed, , if dependencies not expressed @ next make, main.o not updated accordingly. simple example, has big impact in big software projects object files stuck in old versions.
question 2: not in little projects. on big projects, first specified object file may contain symbol sec specified object file needs linked; total reply is: not in little projects, it's best used future projects.
question 3: target order not matter.
question 4: echo goes after dependencies:
test: car.o student.o house.o main.o echo "this test" $(cxx) $(cxxflags) -o test main.o car.o student.o house.o c++ makefile
Comments
Post a Comment