[英]C++ Makefile 3 files
I have a makefile problem. 我有一个makefile问题。 I know how to create a makefile for two, but not four different files including header files... 我知道如何为两个但不是四个不同的文件(包括头文件)创建一个makefile。
There are four files, main.cpp Dictionary.h Dictionary.cpp and Cinco.h 有四个文件,main.cpp Dictionary.h Dictionary.cpp和Cinco.h
Cincotest: main.o Cinco.o
g++ -o p3 main.o Cinco.o
main.o: main.cpp Cinco.h
g++ -c main.cpp
Dictionary.o: Dictionary.cpp Dictionary.h
g++ -c .cpp
# clean up
clean:
rm -f p4 *.o *~
Do we need the other files code or could we get help here?? 我们是否需要其他文件代码,还是可以在这里获得帮助?
If you know the answer and could input the new code that would be perfect ;) 如果您知道答案,并且可以输入完美的新代码;)
It looks to me like a fairly standard way of organizing code - .cpp
and a .h
header file to go with it. 在我看来,这是一种相当标准的组织代码的方式.cpp
和.h
头文件。
The rules that you have are sufficient. 您拥有的规则就足够了。 Unless your main.cpp
also #include-s the Dictionary.h
header file, or your dictionary.cpp
also #include-s the Cinco.h
, in which case: 除非您的main.cpp
也#include-s Dictionary.h
头文件,或者您的dictionary.cpp
也#include-s Cinco.h
,在这种情况下:
main.o: main.cpp Cinco.h Dictionary.h
g++ -c main.cpp
Dictionary.o: Dictionary.cpp Cinco.h Dictionary.h
g++ -c .cpp
A makefile
is just a dependency list. 一个makefile
只是一个依赖列表。 For each *.o
file, it's dependencies are all the source files needed to compile it. 对于每个*.o
文件,其依赖项是编译该文件所需的所有源文件。 If in your main.cpp
you #include Dictionary.h
, then a change to Dictionary.h
means that main.cpp
needs to be recompiled, of course. 如果在main.cpp
#include Dictionary.h
,那么对Dictionary.h
的更改意味着当然需要重新编译main.cpp
。 Therefore, your dependency rule would indicate the same way. 因此,您的依赖项规则将指示相同的方式。
Since you're using g++
, you can also use g++
to write your dependency rules for you. 由于您使用的是g++
,因此您也可以使用g++
为您编写依赖关系规则。 Try: 尝试:
g++ -MM -MF main.deps main.cpp
See gcc
's man page for more information. 有关更多信息,请参见gcc
的手册页。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.