English 中文(简体)
将多个 C+++ 文件一起与 sepearate 一起汇编
原标题:Compiling multiple C++ files together versus sepearately

对于大型 C++ 工程, 最好将所有 cpp 文件编译为 g++ 的大调或单独编译, 然后将结果或介于中间的东西( 如同时编辑命名空间/ 模块/ 子目录的所有文件) 。

实际的区别是什么?哪种方法最快,为什么?

最佳回答

比较好的做法是将文件精密地汇编并链接, 因为它只允许您在修改时对受影响的文件进行重新拼凑。 因此, 在第一个构建后, 构建时间会最小化 。

事实上,由于上述原因,大部分时间都使用这种方法准备文件。

问题回答

有个把戏,说你有一堆文件

file1.cpp
file2.cpp
... 
fileN.cpp

然后您可以创建“ master. cpp” 文件 :

#include "file1.cpp"
#include "file2.cpp"
...
#include "fileN.cpp"

并汇编它。

这样您就可以轻松比较单个文件和文件集的构建时间 。

如果您在 UNIX 上, 请使用“ 时间” 来获得 gcc 呼叫的执行时间 。

当然,瓶颈是“ 聚合” 操作 - 连接阶段。 有一个 GOLD 链接( < a href=" http:// en.wikipedia. org/ wiki/ Gold_ 28linker% 29" rel = "nofollow" > wikipedia ) 解决了 ELF 文件的这个问题 。

显然,同时启动多个编译器进程将导致更高效的 CPU 使用,因为您正在使用一个多核心或多CPU 系统。 但是,整个项目的主要瓶颈仍然是链接,它实际上必须从所有对象文件中创建一个可执行的链接。

除此之外, 它真的取决于项目本身 。 文件之间有多少依赖关系? 哪些需要首先编译? 您最好让您的建筑系统来做这些决定 。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签