如何在 Visual Studio 中使用 makefile?
我听说过很多关于 makefile 以及它们如何简化编译过程的内容。 我用的是VS2008。 有人可以推荐一些在线参考资料或书籍,让我可以找到更多有关如何处理它们的信息吗?
I heard a lot about makefiles and how they simplify the compilation process. I'm using VS2008. Can somebody please suggest some online references or books where I can find out more about how to deal with them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
实际上,我使用 makefile 来构建调用 devenv 构建特定项目之前所需的任何依赖项,如下所示:
您还可以使用 msbuild 工具执行相同的操作:
在我看来,这比尝试找出过于复杂的视觉工作室项目管理方案。
I actually use a makefile to build any dependencies needed before invoking devenv to build a particular project as in the following:
You can also use the msbuild tool to do the same thing:
In my opinion, this is much easier than trying to figure out the overly complicated visual studio project management scheme.
VS 相当于 makefile 是一个“解决方案”(我知道过于简单化了)。
The VS equivalent of a makefile is a "Solution" (over-simplified, I know).
总结一下完整的解决方案...
有 2 个选项:
该快捷方式存在于“开始”菜单中。 查看 makefile 内部是否有任何“设置”操作。 操作显示为冒号之前的第一个单词。 通常,所有好的 makefile 都有一个“all”操作,因此您可以键入: NMAKE all
大多数设计良好的开源解决方案都会提供一个带有设置操作的 makefile,以便为您生成 Visual Studio 项目文件,因此请首先在 Makefile 中查找这些文件。
否则,您需要将每个文件或文件组和文件夹拖放到您在 Visual Studio 中创建的每个新项目中。
希望这可以帮助。
To summarize with a complete solution...
There are 2 options:
The shortcut exists in your Start Menu. Look inside the makefile to see if there are any 'setup' actions. Actions appear as the first word before a colon. Typically, all good makefiles have an "all" action so you can type: NMAKE all
Most well designed open source solutions provide a makefile with a setup action to generate Visual Studio Project Files for you so look for those first in your Makefile.
Otherwise you need to drag and drop each file or group of files and folders into each New Project you create within Visual Studio.
Hope this helps.
Makefile 和构建文件用于自动化构建。 如果您使用 MSBuild 或 NAnt 等脚本,则可以直接从命令行构建项目或解决方案。 这反过来又使得自动化构建成为可能,并由构建服务器运行它。
除了构建解决方案之外,构建脚本通常还包括运行单元测试、报告代码覆盖率和复杂性等任务。
Makefiles and build files are about automating your build. If you use a script like MSBuild or NAnt, you can build your project or solution directly from command line. This in turn makes it possible to automate the build, have it run by a build server.
Besides building your solution it is typical that a build script includes task to run unit tests, report code coverage and complexity and more.
如果您询问实际的命令行 makefile,则可以导出 makefile,或者可以从命令行对解决方案文件调用 MSBuild。 您到底想用 makefile 做什么?
您可以在 SO 上搜索 MSBuild 以获取更多详细信息。
If you are asking about actual command line makefiles then you can export a makefile, or you can call MSBuild on a solution file from the command line. What exactly do you want to do with the makefile?
You can do a search on SO for MSBuild for more details.
Microsoft 程序维护实用程序 (NMAKE.EXE) 是一种根据描述文件中包含的命令构建项目的工具。
NMAKE 参考
The Microsoft Program Maintenance Utility (NMAKE.EXE) is a tool that builds projects based on commands contained in a description file.
NMAKE Reference
回答具体问题...
此链接将通过将 Makefile 与 Visual Studio 进行映射来很好地介绍 Makefile。
面向 Visual Studio 开发人员的 Makefile 简介
Makefile 功能强大且灵活,但可能不是简化过程的最佳解决方案。 考虑一下 CMake,它很好地抽象了构建过程,这在这个链接中进行了解释。
面向 Visual Studio 开发人员的 CMake
To answer the specific questions...
This link will give you a good introduction into Makefiles by mapping it with Visual Studio.
Introduction to Makefiles for Visual Studio developers
Makefiles are powerful and flexible but may not be the best solution to simplify the process. Consider CMake which abstracts the build process well which is explained in this link.
CMake for Visual Studio Developers
UNIX 专家可能会告诉你这一点。 :)
您可以在 VS 中使用 makefile,但是当您这样做时,它会绕过 MSVC IDE 中的所有内置功能。 Makefile 基本上是构建器的reinterpret_cast。 IMO 最简单的事情就是使用解决方案。
A UNIX guy probably told you that. :)
You can use makefiles in VS, but when you do it bypasses all the built-in functionality in MSVC's IDE. Makefiles are basically the reinterpret_cast of the builder. IMO the simplest thing is just to use Solutions.