在 GNU c++ 编译器中运行一个包含多个源文件的程序

2023-10-17C/C++开发问题
5

本文介绍了在 GNU c++ 编译器中运行一个包含多个源文件的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在 Windows 7 操作系统上使用 DEV GNU c++ 编译器.我需要知道如何编译具有多个源文件的程序.这是示例,

I am using DEV GNU c++ compiler on windows 7 OS. I need to know how a program with more than one source file can be compiled. here is example,

#FILE1
void f1()
{
   printf("this is another file under same program");
}

#FILE2

int main()
{
   f1();
   return 0;
}

实际上我需要这个来测试静态、extern 类说明符如何处理多个文件.所以只有我现在必须学习如何在 C 中的单个程序中处理多个文件..

Actually I need this to test how static, extern class specifier works with more than one file. So only I have to learn now how works with more than one files in a single program in C..

提前致谢

推荐答案

多个文件"的技术术语将是 翻译单位:

The technical term for 'multiple files' would be translation units:

g++ file1.cpp file2.cpp -o program

或者你把编译和链接分开

Or you separate compilation and linking

g++ -c file1.cpp -o file1.o
g++ -c file2.cpp -o file2.o

# linking
g++ file1.o file2.o -o program   

但这通常没有意义,除非您有一个更大的项目(例如使用 make)并希望减少构建时间.

But that usually doesn't make sense unless you have a larger project (e.g. with make) and want to reduce build times.

这篇关于在 GNU c++ 编译器中运行一个包含多个源文件的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6