Windows 中的 Makefile

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

Makefile in Windows

cwindowsmakefile

提问by Renjith G

I have a folder named 'X'. In XI have two subfolders: srcand include.

我有一个名为'X'. 在X我有两个子文件夹:srcinclude

The srcfolder contains a C file main.c, and the includefolder contains a file main.h.

src文件夹包含一个 C 文件main.c,该include文件夹包含一个文件main.h

I want to write a makefile to build these files(from folder X) in windows command prompt. I have tried a lot but with no effect. First of all I need the make file format in Linux for this, and once I have that i will do that in Windows.

我想编写一个 makefile 来X在 Windows 命令提示符下构建这些文件(来自文件夹)。我尝试了很多但没有效果。首先,我需要 Linux 中的 make 文件格式,一旦我有了它,我将在 Windows 中执行此操作。

Can anybody help me in doing this?

有人可以帮我做这件事吗?

回答by Gal Goldman

Try the following links, in there you'll find the format, and basically all that you need to build your Makefile:

尝试以下链接,您将在其中找到格式,以及构建 Makefile 所需的基本内容:

http://mrbook.org/blog/tutorials/make/

http://mrbook.org/blog/tutorials/make/

http://www.opussoftware.com/tutorial/TutMakefile.htm

http://www.opussoftware.com/tutorial/TutMakefile.htm

http://oucsace.cs.ohiou.edu/~bhumphre/makefile.html

http://oucsace.cs.ohiou.edu/~bhumphre/makefile.html

回答by Nick

Once you've made your Makefile, you can use MinGW's mingw32-make - A Windows native build of GNU make.

创建 Makefile 后,您可以使用 MinGW 的 mingw32-make - GNU make 的 Windows 本机构建。

回答by Gamma032

  1. Open the folder (X) in file explorer.

  2. Right click anywhere > new > text document.

  3. Right click on the file > rename > remove .txtextension.

  4. Open up the makefile with your favorite text editor.

  1. X在文件资源管理器中打开文件夹 ( )。

  2. 右键单击任意位置 > 新建 > 文本文档。

  3. 右键单击文件 > 重命名 > 删除.txt扩展名。

  4. 使用您喜欢的文本编辑器打开 makefile。

回答by Prox

You can use NMake, which is the windows alternative do Linux make. It is a command-line tool included with Visual Studio.

您可以使用NMake,它是 Linux make 的 Windows 替代品。它是 Visual Studio 附带的命令行工具。

Although the syntax is very similar, you will find some differences. So the makefile that works on Linux may not work directly with NMake in windows.

尽管语法非常相似,但您会发现一些不同之处。所以在Linux上运行的makefile在windows下可能不能直接和NMake一起运行。

In Linux, these lines for example:

在 Linux 中,这些行例如:

gcc -c main.cpp -o main.o
gcc -o app main.o -lstdc++

In Windows, probably should be changed to:

在 Windows 中,可能应该改为:

cl.exe /c main.cpp /Fomain.o
link.exe /OUT:app.EXE main.o

So the makefile require edition to work with NMAKE in windows.

因此,makefile 需要版本才能在 Windows 中与 NMAKE 一起使用。

To use the makefile "as is", you should try a tool to mimic Linux commands in Windows, like Cygwin.

要“按原样”使用 makefile,您应该尝试使用一种工具来模拟 Windows 中的 Linux 命令,例如Cygwin