Using G++ to compile multiple .cpp and .h files(使用 G++ 编译多个 .cpp 和 .h 文件)
问题描述
我刚刚继承了一些用一个 cpp 文件编写的糟糕的 C++ 代码,该文件包含主函数和一堆其他函数.还有 .h 文件包含类及其函数定义.
I've just inherited some C++ code that was written poorly with one cpp file which contained the main and a bunch of other functions. There are also .h files that 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 separated 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.
即
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 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 G++ 编译多个 .cpp 和 .h 文件
基础教程推荐
- CString 到 char* 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
