我在 Windows 7 操作系统上使用 DEV GNU c++ 编译器。我需要知道如何编译具有多个源文件的程序。 这是例子,
#FILE1
void f1()
{
printf("this is another file under same program");
}
#FILE2
int main()
{
f1();
return 0;
}
实际上我需要这个来测试静态的外部类说明符如何处理多个文件。所以我现在只需要学习如何在 C 中的单个程序中处理多个文件..
提前致谢
最佳答案
“多个文件”的技术术语是 translation units :
g++ file1.cpp file2.cpp -o program
或者你把编译和链接分开
g++ -c file1.cpp -o file1.o
g++ -c file2.cpp -o file2.o
# linking
g++ file1.o file2.o -o program
但这通常没有意义,除非您有一个更大的项目(例如使用 make
)并希望减少构建时间。
关于c++ - 在 GNU c++ 编译器中运行一个包含多个源文件的程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11155327/