本文介绍了C ++:创建带有两个可执行文件的makefile? C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个共享一个类的C ++程序. progOne.cpp和progTwo.cpp.它们都与适当的fileInfo.h文件共享一个类fileInfo.cpp.

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.

这就是我尝试创建Makefile的方式.

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.

我得到一个错误:make:'all'不需要做任何事情.

I get the error: make: nothing to be done for 'all'.

推荐答案

您需要:

all: progOne progTwo

这告诉我们all取决于progOneprogTwo.如果使用all: progOne.cpp ...,则如果progOne.cpp已经存在,make将不需要执行任何操作,并说什么都不要做".

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

当然,接下来,您必须解释一下progOneprogTwo如何依赖源文件,以便在更新源文件时,它会重建可执行文件.

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.

您可能还想将progOne.cpp的任何头文件添加到依赖项,例如progOne: progOne.cpp progOne.h-如果更新progOne.h,则将重建程序.

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.

这篇关于C ++:创建带有两个可执行文件的makefile? C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 02:17