源文件的编译顺序是如何决定的?
我有一个工作区,其中包含许多我编译的 *.c 文件。 (我可以使用任何工具链,例如 MSVC6.0 或 gcc 等)
首先编译哪个源文件?
后续编译的文件顺序是如何决定的?
I have a workspace containing many *.c files, which I compile. (I could use any toolchain say MSVC6.0, or gcc etc)
Which source file is compiled first?
How is the order of the files to be compiled subsequently decided?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
C 标准没有指定编译顺序。
由于不需要像 C++ 那样构造全局对象,因此 C 中不存在编译顺序相关的情况。
The order of compilation is not specified by the C standard.
Since there is no need for the construction of global objects like in C++, there is no situation where the order of compilation is relevant in C.
一般来说,这在任何地方都没有指定。 特别是当使用例如。 并行make,编译的顺序几乎是任意的。
Generally, this is not specified anywhere. Especially when using eg. parallel make, the order of compilation is pretty much arbitrary.
VC:按项目文件夹,然后按字母顺序排列。
GCC:根据make文件顺序
为什么这很重要?,完成顺序不计量也不影响最终的构建结果。
VC: By project folder, then alphabetically.
GCC: according to the make file order
Why is this important?, the completion order don't meter and doesn't effect the final build result.
使用
make
:作为 jpalecek 建议,并发构建可能会更复杂。
GNU make 文档中的一些引用:
...
With
make
:As jpalecek suggests, concurrent builds may be more complicated.
Some quotes from the GNU make docs:
...
如果这很重要,那么您确实需要在 makefile 中设置依赖项,以确保某些依赖项先于其他依赖项构建。 事实上,你应该首先问自己为什么这很重要。
If it matters then you really need to set dependencies in your makefile to ensure some are built before others. Really you should first ask yourself why it matters.