C++ 如何在 Visual Studio 中使用 makefile?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/314553/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use makefiles in Visual Studio?
提问by chester89
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?
我听说了很多关于 makefile 以及它们如何简化编译过程的信息。我正在使用 VS2008。有人可以推荐一些在线参考资料或书籍,我可以在其中找到有关如何处理它们的更多信息吗?
采纳答案by John Dibling
A UNIX guy probably told you that. :)
一个 UNIX 人可能告诉过你。:)
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.
您可以在 VS 中使用 makefile,但这样做时会绕过 MSVC IDE 中的所有内置功能。Makefile 基本上是构建器的 reinterpret_cast。IMO 最简单的事情就是使用解决方案。
回答by Alessandro Jacopson
The Microsoft Program Maintenance Utility (NMAKE.EXE) is a tool that builds projects based on commands contained in a description file.
Microsoft 程序维护实用程序 (NMAKE.EXE) 是一种基于描述文件中包含的命令构建项目的工具。
回答by ap-osd
To answer the specific questions...
要回答具体问题...
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?
我正在使用 VS2008。有人可以推荐一些在线参考资料或书籍,我可以在其中找到有关如何处理它们的更多信息吗?
This link will give you a good introduction into Makefiles by mapping it with Visual Studio.
此链接将通过将 Makefile 与 Visual Studio 映射,为您提供对 Makefile 的良好介绍。
Introduction to Makefiles for Visual Studio developers
面向 Visual Studio 开发人员的 Makefile 简介
I heard a lot about makefiles and how they simplify the compilation process.
我听说了很多关于 makefile 以及它们如何简化编译过程的信息。
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.
Makefile 功能强大且灵活,但可能不是简化流程的最佳解决方案。考虑 CMake,它很好地抽象了构建过程,此链接中对此进行了解释。
回答by Jon Trauntvein
I actually use a makefile to build any dependencies needed before invoking devenv to build a particular project as in the following:
在调用 devenv 构建特定项目之前,我实际上使用了一个 makefile 来构建所需的任何依赖项,如下所示:
debug: coratools_debug
devenv coralib.vcproj /build debug
coratools_debug: nothing
cd ../coratools
nmake debug
cd $(MAKEDIR)
You can also use the msbuild tool to do the same thing:
你也可以使用 msbuild 工具来做同样的事情:
debug: coratools_debug
msbuild coralib.vcxproj /p:Configuration=debug
coratools_debug: nothing
cd ../coratools
nmake debug
cd $(MAKEDIR)
In my opinion, this is much easier than trying to figure out the overly complicated visual studio project management scheme.
在我看来,这比试图找出过于复杂的 Visual Studio 项目管理方案要容易得多。
回答by Joel Coehoorn
The VS equivalent of a makefile is a "Solution" (over-simplified, I know).
与 makefile 等效的 VS 是一个“解决方案”(我知道过于简化了)。
回答by justdan23
To summarize with a complete solution...
总结一个完整的解决方案......
There are 2 options:
有2个选项:
- Use NMAKE from the Developer Command Prompt for Visual Studio
- 从 Visual Studio 的开发人员命令提示符使用 NMAKE
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
快捷方式存在于您的开始菜单中。查看 makefile 内部是否有任何“设置”操作。操作显示为冒号前的第一个单词。通常,所有好的 makefile 都有一个“all”操作,因此您可以键入:NMAKE all
- Create a Solution and Project Files for each binary.
- 为每个二进制文件创建一个解决方案和项目文件。
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.
大多数设计良好的开源解决方案都提供了一个带有设置操作的 makefile,用于为您生成 Visual Studio 项目文件,因此请在您的 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.
否则,您需要将每个文件或一组文件和文件夹拖放到您在 Visual Studio 中创建的每个新项目中。
Hope this helps.
希望这可以帮助。
回答by mmiika
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.
Makefile 和构建文件是关于自动化构建。如果您使用 MSBuild 或 NAnt 等脚本,则可以直接从命令行构建项目或解决方案。这反过来又使构建自动化成为可能,让它由构建服务器运行。
Besides building your solution it is typical that a build script includes task to run unit tests, report code coverage and complexity and more.
除了构建您的解决方案之外,构建脚本通常还包括运行单元测试、报告代码覆盖率和复杂性等任务。
回答by Tim
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?
如果您询问实际的命令行生成文件,那么您可以导出生成文件,或者您可以从命令行对解决方案文件调用 MSBuild。你到底想用 makefile 做什么?
You can do a search on SO for MSBuild for more details.
您可以在 SO for MSBuild 上搜索以获取更多详细信息。