程序员多久会被要求编写一个 makefile 文件?

发布于 2024-08-27 11:10:45 字数 75 浏览 7 评论 0原文

对于程序员来说,makefile 是一个高级问题还是一个普遍问题? 对于一个C++程序员来说,他多久会被要求写一个makefile文件?

Is makefile an advanced problem or a general problem for a programmer?
For a C++ programmer, how often will he be asked to write a makefile file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

初心未许 2024-09-03 11:10:45

没有人写过 Makefile。他们获取现有的 Makefile 并对其进行修改。

庆幸的是您不必处理 IMakefile。 (对于那些幸运地从未处理过这个问题的人,或者那些设法忘记的人来说,IMakefile 是一个类似于基于 X Window 系统的项目的元 Makefile 的文件,它将用于生成一个知道的 Makefile不用说,它很糟糕。)

Nobody ever writes a Makefile. They take an existing Makefile and modify it.

Just be thankful you don't have to deal with IMakefile. (For those of you who were lucky enough to never deal with this, or who have managed to forget, IMakefile was a file that was sort of a meta-Makefile for X Window System based projects which would be used to generate a Makefile that knew where you'd installed all your X Windows libraries and binaries. Needless to say, it sucked.)

一紙繁鸢 2024-09-03 11:10:45

设置有意义的构建系统是工艺的一部分。我希望任何非超级初级开发人员都能够提出一个 makefile。

Setting up a meaningful build system is part of the craft. I'd expect any non-super-junior developer to be able to come up with a makefile.

雄赳赳气昂昂 2024-09-03 11:10:45

他经常被要求开始一个全新的项目,该项目与可以调整构建脚本的现有项目不同。我想这不是一个好的答案,但根据我的经验,总是有一些我可以适应的代码/资源/构建脚本。

另一方面,对于任何 C++ 程序员来说,了解他的代码是如何构建的非常重要。 Makefile、Ant 脚本等只是实现机制。所以我认为学习是足够重要的。

As often as he is asked to start on a brand new project, which is not similar to an existing project whose builds scripts can be adapted. That is not a good answer I guess, but in my experience there has always been some code/resources/build scripts that I can adapt.

On a different note, for any C++ programmer, it is important to learn how his code is built. Makefiles, Ant scripts etc are just the implementation mechanism. So I think it is important enough to learn.

转身以后 2024-09-03 11:10:45

程序员需要知道如何构建他们的项目。通常(根据我的经验)“生产版本”基于原始程序员的 makefile。许多程序员在他们的整个职业生涯中只是盲目地摸索着整理他们的 makefile,但每个程序员都必须这样做。

Programmers need to know how to build their projects. Typically (in my experience) the 'production build' is based on the original programmer's makefile. Many programmers go their entire careers just fumbling blindly when putting together their makefiles, but every programmer has to do it.

谁对谁错谁最难过 2024-09-03 11:10:45

我从来没有认为 makefile 是个问题,它们非常有用......

频率取决于您正在使用的平台和您的角色。

例如,在某些组织中,有一个相当固定的构建文件,不经常更改,而在其他组织中,则经常更改。有些组织依靠 IDE 来处理构建等。您不必是构建工程师。

我认为大多数 C/C++ 开发人员至少应该对 makefile 的工作原理有一些基本的了解,尽管他们不必是专家。在我的母校,这是一年级计算机科学的一部分。

I have never thought of makefiles as problems, they are quite usefull...

The frequency would depend on the platform that you're using and your role.

For example, in some organizations there is a fairly fixed build file that doesn't often change, while in others there are frequent changes. Some organizations rely on the IDE to deal with the build, etc. You don't have to be the build engineer.

I think that most C/C++ developers should have at least some fundamental understanding of how makefiles work, though they don't have to be gurus. In my alma mater, that is part of first-year CS.

醉城メ夜风 2024-09-03 11:10:45

需要注意的一件事是,如果构建系统以模块化方式设置,一种做法不是为整个事情构建一个巨大的 makefile,而是为可以从主 makefile 递归调用的位构建 makefile。这是一个很棒的功能,因为它意味着不同的产品(库?)可以构建为单独的单元,通常是并行的。

Makefile 旨在自动化构建过程。因此,它们绝对不是一件苦差事。它们可以节省您一直编写 gcc -c *.c 等内容。不仅如此,正确编写的 makefile 还包含清理、重建等功能。在我的大多数项目中,makerebuild 正是这样做的 - 清理所有内容并重新开始。

Makefile 确实很有用。我说得还不够。

One thing to note is that, if the build system is set up in a modular way one practice isn't to build one huge makefile for the whole thing but makefiles for bits that can be called from the master makefile recursively. This is a great feature as it means different products (libraries?) can be built as separate units, often in parallel.

Makefiles are designed to automate the build process. Therefore, they are most definitely not a chore; they save you writing gcc -c *.c etc all the time. Not only that, but a properly written makefile has phonies for clean, rebuild etc. On most of my projects, make rebuild does exactly that - cleans everything and starts again.

Makefiles are really useful. I can't say that enough.

左秋 2024-09-03 11:10:45

即使您使用的 IDE 可以为您处理构建项目的细节,makefile 仍然非常有用。有时,您需要在构建过程中拥有一些额外的功能,例如运行预处理步骤以编程方式生成 C++ 文件(如果您使用 Qt,则可能需要在上运行 moc您可能需要处理 .idl 文件以生成实现文件),或者作为将文件复制到目标的构建后步骤。在这些情况下,您通常有两种选择:

  • 每次作为构建前或构建后步骤运行脚本,这意味着每次构建应用程序时都会重新构建应用程序
  • 创建一个 makefile 来执行将体现依赖关系的操作规则,以便仅当输入文件的时间戳比输出文件的时间戳新时才会调用该步骤。构建一个已经是最新的项目不会有任何作用

如果 C++ 开发人员不在 Linux/Unix 上工作,他们可能会工作很多年而不需要创建 Makefile,但是一个体面的开发人员会寻求理解 Makefile 是如何工作的可能会改善您当前工作流程的一部分。

Even if you are using an IDE that deals with the details of building the project for you, makefiles can still be very useful. Occasionally you need to have some extra functionality as part of your build process, for instance to run a pre-processing step to generate a c++ file programmatically (if you use Qt then you may need to run moc on your header files or rcc on your resource files. You might need to process an .idl file to generate an implementation file), or as a post-build step to copy files to a destination. In these cases you typically have two choices:

  • run the scripts as pre- or post-build steps every time, which means the app will be rebuilt every time you build it
  • create a makefile to perform the action which will embody the dependency rule so that the step will only be invoked if the timestamp of the input file is newer than that of the output file. Building a project that is already up to date will do nothing

A C++ developer may go for many years without needing to create a Makefile if they're not working on Linux/Unix, but a decent developer will seek to understand how Makefiles work as they will probably improve part of your current workflow.

夏末染殇 2024-09-03 11:10:45

我想这取决于...就

我个人而言,我对 Makefile 的语法非常着迷。在对象的路径上执行任何类型的简单操作都是非常棘手的。

另一方面,能够构建是必要的,理解编译行上的各种参数也是必要的。虽然也许不适合初级学生。

离开学校仅仅一年后,我就不得不重写我们应用程序的构建系统。我使用 scons 完成了它,效果很好。构建时间从 1 小时 30 分减少到仅仅 10 分钟,因为我终于能够进行并行编译并自动本地复制所使用的库。

其原则是:如果您要求某人采用构建机制,请不要将 Makefile 强加给他。让他选择一个更新的工具。

I suppose it depends...

Personally, I am quite mesmerized by the syntax of Makefiles. Doing any kind of even a simple operation on the paths of the object is ever so tricky.

On the other hand, being able to build is just necessary, and understanding the various arguments on the compile line is too. Though perhaps not for a junior.

I had to rewrite the build system of our application barely a year after I left school. I did it using scons and it worked great. Build time went from 1h30 to barely 10m because I was finally able to have parallel compilation and put an automatic local replication of the libraries used in place.

The morale is: if you ask someone to pick up a build mechanism, do not force Makefile on him. Let him pick a more recent tool.

柒七 2024-09-03 11:10:45

make 的一个强大部分是您可以在每个规则中编写的 shell 代码。
所以不仅学习make很重要,了解像bash这样的shell语言并将其应用到项目中也是非常有用的

A powerful part of make is the shell code that you can write in each rule.
So not only learning make is important, but understanding a shell language like bash and applying it to a project is very useful

小糖芽 2024-09-03 11:10:45

这取决于您的项目使用的工具/库/框架。对于我的工作,我使用 Qt 进行编码,因此我永远不必编写 Makefile,因为 qmake 会为我编写 Makefile,尽管我确实必须知道如何创建 qmake 项目文件。

我坦率地承认,如果不从头开始学习,我可能无法编写除最简单的 Makefile 之外的任何内容。我认为这种情况不会很快改变,因为只有在被迫的情况下我才会学习它。为什么要学习一些你可能永远不需要的东西?

It depends on the tools/libraries/frameworks you are using for your project. For my job I code using Qt so I never have to write a Makefile as qmake does it for me although I do have to know how to create a qmake project file instead.

I freely admit I probably couldn't write anything beyond the simplest Makefile without having to learn it all from scratch. I don't see that changing anytime soon as I would only learn it if I was forced to. Why learn something you may never need?

欢烬 2024-09-03 11:10:45

在过去的五年里,我没有被要求编写 makefile。有时我可以修改现有的 makefile。

但是,当您拥有无需 make 程序即可完成工作的工具时,就没有必要关心 makefile。关于您的问题,当 C++ 程序员被要求编写这样的文件时:这取决于情况。

I haven't been asked to write a makefile in the last five years. Sometimes I could modify an existing makefile.

But when you have tools that make the job without the make program, it's not necessary to care for makefiles. Regarding your question, when a C++ programer has been asked for writing such a file: It depends.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文