I have two C++ programs that both share a class. progOne.cpp and progTwo.cpp. They both share a class, fileInfo.cpp with the appropriate fileInfo.h file.
This is how I tried to create the makefile.
all: progOne.cpp progTwo.cpp
progOne: progOne.cpp fileInfo.cpp
g++ progOne.cpp fileinfo.cpp -o progOne
progTwo: progTwo.cpp fileinfo.cpp
g++ progTwo.cpp fileinfo.cpp -o progTwo.
I get the error: make: nothing to be done for 'all'.
You need:
all: progOne progTwo
This tells make that all depends on progOne and progTwo. If you use all: progOne.cpp ... then if progOne.cpp already exists, make will not need to do anything, and says "nothing to be done for all".
Of course, next you have to explain to make how progOne and progTwo depend on the source files, so that when you update the source-file, it rebuilds the executable file.
You may also want to add any header files for progOne.cpp to the dependencies, e.g. progOne: progOne.cpp progOne.h - so that if progOne.h is updated, the program is rebuilt.
来源:https://stackoverflow.com/questions/34078471/c-creating-a-makefile-with-two-executables-c