如何在 Windows 中使用手写的 makefile 编译和构建 C++ 应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2532290/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:11:47  来源:igfitidea点击:

How to compile and build c++ application with hand written makefile in windows?

c++windowsmakefile

提问by user198729

Can someone provide a HelloWorld demo ?

有人可以提供一个 HelloWorld 演示吗?

回答by Daniel Earwicker

If you know about makefiles but are trying to cope with the lack of tools on a default Windows install:

如果您了解 makefile 但正在尝试解决默认 Windows 安装中缺少工具的问题:

Get cygwin.

获取 cygwin。

If you want to learn about makefiles:

如果您想了解 makefile:

This is actually quite a complex question. Firstly for hello world, you wouldn't need linking of several files, so the makefile could be simplified, but then wouldn't teach you what you need to know.

这实际上是一个相当复杂的问题。首先,对于 hello world,您不需要链接多个文件,因此可以简化 makefile,但不会教您需要了解的内容。

In a real program you need to link several files, you need to use makefile variables to reduce repetition, etc. So a short example would contain a bunch of stuff with no apparent purpose. So what you need is a good tutorial.

在一个真正的程序中,你需要链接几个文件,你需要使用 makefile 变量来减少重复等。所以一个简短的例子将包含一堆没有明显目的的东西。所以你需要的是一个很好的教程。

This one is pretty good.Jump in at that page but keep reading, as the stuff on the first page is not the maintainable approach (though it is necessary to know about it).

这个很不错。跳到那个页面但继续阅读,因为第一页上的内容不是可维护的方法(尽管有必要了解它)。

If you just want to write Windows programs:

如果您只想编写 Windows 程序:

Don't bother with makefiles. Use Visual Studio project files and a solution file to tie them together. Most open source projects seem to distribute VS project files for Windows (if anything) and use gnu makefor other platforms. Visual Studio is available in a free "Express" edition.

不要打扰makefile。使用 Visual Studio 项目文件和解决方案文件将它们联系在一起。大多数开源项目似乎为 Windows(如果有的话)分发 VS 项目文件,并make为其他平台使用 gnu 。Visual Studio 提供免费的“Express”版本。

回答by Nader Shirazie

There's an nmake tutorial available here(nmake is what comes with visual studio).

这里有一个NMAKE教程可用这里(NMAKE是什么来与Visual Studio)。

Is there something more specific you're trying to do? It would help get a better answer. Are there some specific differences with Windows that concern you?

你有什么更具体的尝试吗?这将有助于获得更好的答案。与 Windows 是否存在一些让您担忧的特定差异?

回答by Paul R

Easiest way is to install cygwinand use a normal makefile.

最简单的方法是安装cygwin并使用普通的 makefile。

回答by Dani

if you are using visual studio - the CSPROJ is the make file - you can try to view it in an editor. with other compilers - you need to check...

如果您使用的是 Visual Studio - CSPROJ 是制作文件 - 您可以尝试在编辑器中查看它。与其他编译器 - 您需要检查...

回答by Dani

If you want to develop Windows applications (as opposed to Posix ones as supported by the bloated Cygwin) from the command line, the best solution is to get the MinGW port of GCC from Twilight Dragon, and the MSYSport of the standard GNU tools such as make. You should also get a copy of the GNU make manual, which is also an excellent tutorial.

如果你想从命令行开发 Windows 应用程序(而不是由臃肿的 Cygwin 支持的 Posix 应用程序),最好的解决方案是从Twilight Dragon获取 GCC 的 MinGW 端口,以及标准 GNU 工具的MSYS端口,例如作为使。您还应该获得一份GNU make 手册,这也是一个很好的教程。