问题描述
我只是继承了一些C ++代码,写得不好,一个cpp文件包含主要和一堆其他功能。还有 .h
文件包含类及其函数定义。
I've just inherited some C++ code which was written poorly with one cpp file which contained the main and a bunch of other functions. There are also .h
files which contain classes and their function definitions.
直到现在程序使用命令 g ++ main.cpp
。现在我已经分类到 .h
和 .cpp
文件,我需要使用makefile或我仍然使用 g ++ main.cpp
命令?
Until now the program was compiled using the command g++ main.cpp
. Now that I've seperated the classes to .h
and .cpp
files do I need to use a makefile or can I still use the g++ main.cpp
command?
推荐答案
在main.cpp之后的其他cpp文件。
list all the other cpp files after main.cpp.
ie
g++ main.cpp other.cpp etc.cpp
等等。
或者你可以单独编译它们。然后,将所有生成的.o文件链接到一起。
Or you can compile them all individually. You then link all the resulting ".o" files together.
这篇关于使用G ++编译多个.cpp和.h文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!