如何包含和编译多个C ++文件? [英] How to include and compile multiple C++ files?
问题描述
我有这些文件: classA.cpp
, classA.h
, classB。 cpp
, classB.h
和 main.cpp
。
所有需要的库都包含在.h文件中。
I have these files: classA.cpp
, classA.h
, classB.cpp
, classB.h
, and main.cpp
.
All needed libraries are included in both .h files.
在 main.cpp
我包括 classA.cpp
和 classB.cpp
。
在 classB.cpp
我包含 classB.h
,在 classA.cpp
中,它是 classA。 h
In main.cpp
I include classA.cpp
and classB.cpp
.
In classB.cpp
I include classB.h
and in classA.cpp
it is classA.h
我按
g ++ main.cpp
g++ main.cpp
(+一些不重要的东西),它运作正常。
(+some unimportant stuff) and it is working perfectly.
但我几乎可以肯定,在我们的讲座中,我们被告知要以不同的方式做到这一点,遗憾的是我现在找不到它。
这是包括的最佳方式和编译?如果没有,那是什么?
But I am almost certainly sure, that on our lectures we were told to do that differently, sadly I can't find it now.
Is this the best way of including and compiling? If not, what is?
推荐答案
简单的方法: g ++ main.cpp ClassA.cpp ClassB。 cpp etc.cpp
更高级的方式你应该使用makefile。
在此输入链接说明
这篇关于如何包含和编译多个C ++文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!