在GNU c ++编译器中运行带有多个源文件的程序 [英] run a program with more than one source files in GNU c++ compiler

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

问题描述

我在Windows 7 OS上使用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;
}

实际上,我需要使用它来测试静态外部类说明符如何与一个文件。因此,现在只有我必须学习如何在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 ++编译器中运行带有多个源文件的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆