C++: Creating a makefile with two executables? C++

旧时模样 提交于 2019-12-01 12:29:49

问题


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'.


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!