MakeFile is not glowing like it is Executable

53 Views Asked by At

This is the code that i have written in my makefile. For some reason it is not letting me execute the make function. When i type "make findName", i get "make: 'findName' is up to date."

findName:       findName.cpp
        g++ -g findName.cpp -o findName;

clean:
        /bin/rm -f findName *.o

backup:
        #tar -zcvf bbrown.assignment4_1.tar.gz *.cpp *.h makeFile readme # will make a tar.gz
        tar -cvf bbrown.findName.tar *.cpp *.sh makeFile readme
1

There are 1 best solutions below

1
On

A message like "make: 'target' is up to date." means that make has decided it doesn't need to run any commands, based on the timestamps of files involved. The make program considers files (and phony targets) to have a tree of prerequisites, and commands associated with creating a file will only be run if the file doesn't exist or has an older timestamp than one of its prerequisites. In big projects, this helps avoid completely rebuilding everything which could take a lot of time, when only a few source files have actually changed: make will determine which commands are actually needed. But this does require setting up the Makefile with accurate prerequisites.

Your Makefile specifies that file findName has one prerequisite: findName.cpp. If make successfully creates findName, then you do nothing else but just type make again, you'll see the "up to date" message: this is a feature. If you edit and save findName.cpp and then run make, it should repeat the g++ command.

But suppose you also have some header files you're including from findName.cpp, say findName.h. If you edit and save findName.h and then run make, you'll get "up to date", since make didn't know to findName.h has effects on findName. You would need to add the prerequisite to fix this:

findName:       findName.cpp findName.h
        g++ -g findName.cpp -o findName

There are various ways to automatically deal with header dependencies like that, but they get into more advanced use of make, and/or using other build tools.