简体   繁体   English

Windows 中的 Makefile

[英]Makefile in Windows

I have a folder named 'X' .我有一个名为'X'的文件夹。 In X I have two subfolders: src and include .X我有两个子文件夹: srcinclude

The src folder contains a C file main.c , and the include folder contains a file main.h . src文件夹包含一个 C 文件main.cinclude文件夹包含一个文件main.h

I want to write a makefile to build these files(from folder X ) in windows command prompt.我想编写一个 makefile 来在 Windows 命令提示符下构建这些文件(来自文件夹X )。 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.首先,我需要 Linux 中的 make 文件格式,一旦我有了它,我将在 Windows 中这样做。

Can anybody help me in doing this?有人可以帮我做这件事吗?

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

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

  1. Open the folder ( X ) in file explorer.在文件资源管理器中打开文件夹 ( X )。

  2. Right click anywhere > new > text document.右键单击任意位置 > 新建 > 文本文档。

  3. Right click on the file > rename > remove .txt extension.右键单击文件 > 重命名 > 删除.txt扩展名。

  4. Open up the makefile with your favorite text editor.使用您喜欢的文本编辑器打开 makefile。

You can use NMake , which is the windows alternative do Linux make.您可以使用NMake ,这是 Linux make 的 Windows 替代品。 It is a command-line tool included with Visual Studio.它是 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM