Как запустить makefile на windows

I have some demos that I downloaded and they come with a Makefile.win and a Makefile.sgi. How can I run these in Windows to compile the demos?

0x6B6F77616C74's user avatar

asked Mar 28, 2010 at 7:48

Kim's user avatar

8

You can install GNU make with chocolatey, a well-maintained package manager, which will add make to the global path and runs on all CLIs (powershell, git bash, cmd, etc…) saving you a ton of time in both maintenance and initial setup to get make running.

  1. Install the chocolatey package manager for Windows
    compatible to Windows 7+ / Windows Server 2003+

  2. Run choco install make

I am not affiliated with choco, but I highly recommend it, so far it has never let me down and I do have a talent for breaking software unintentionally.

answered Jul 15, 2019 at 15:05

ledawg's user avatar

ledawgledawg

2,4151 gold badge11 silver badges17 bronze badges

2

If you have Visual Studio, run the Visual Studio Command prompt from the Start menu, change to the directory containing Makefile.win and type this:

nmake -f Makefile.win

You can also use the normal command prompt and run vsvars32.bat (c:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools for VS2008). This will set up the environment to run nmake and find the compiler tools.

answered Mar 28, 2010 at 7:50

Marcelo Cantos's user avatar

Marcelo CantosMarcelo Cantos

181k38 gold badges328 silver badges365 bronze badges

16

Check out GnuWin’s make (for windows), which provides a native port for Windows (without requiring a full runtime environment like Cygwin)

If you have winget, you can install via the CLI like this:

winget install GnuWin32.Make

Also, be sure to add the install path to your system PATH:

C:\Program Files (x86)\GnuWin32\bin

KyleMit's user avatar

KyleMit

30.6k67 gold badges463 silver badges666 bronze badges

answered Jun 6, 2013 at 13:41

Sean Lynch's user avatar

Sean LynchSean Lynch

6,2872 gold badges43 silver badges45 bronze badges

3

Check out cygwin, a Unix alike environment for Windows

answered Mar 28, 2010 at 7:50

Frank's user avatar

FrankFrank

2,3731 gold badge19 silver badges17 bronze badges

4

Here is my quick and temporary way to run a Makefile

  • download make from SourceForge: gnuwin32
  • install it
  • go to the install folder

C:\Program Files (x86)\GnuWin32\bin

  • copy the all files in the bin to the folder that contains Makefile

libiconv2.dll libintl3.dll make.exe

  • open the cmd (you can do it with right click with shift) in the folder that contains Makefile and run

make.exe

done.

Plus, you can add arguments after the command, such as

make.exe skel

Maria Ines Parnisari's user avatar

answered Oct 20, 2017 at 3:59

alan9uo's user avatar

alan9uoalan9uo

1,0211 gold badge11 silver badges17 bronze badges

4

If you install Cygwin. Make sure to select make in the installer. You can then run the following command provided you have a Makefile.

make -f Makefile

https://cygwin.com/install.html

answered Feb 14, 2019 at 1:24

sunny0402's user avatar

sunny0402sunny0402

911 silver badge2 bronze badges

I use MinGW tool set which provides mingw32-make build tool, if you have it in your PATH system variables, in Windows Command Prompt just go into the directory containing the files and type this command:

mingw32-make -f Makefile.win

and it’s done.

answered Jun 27, 2020 at 15:55

WENDYN's user avatar

WENDYNWENDYN

6707 silver badges15 bronze badges

1

I tried all of the above. What helps me:

  1. Download the mingw-get.
  2. Setup it.
  3. Add something like this C:\MinGW\bin to environment variables.
  4. Launch (!important) git bash. Power shell, developer vs cmd, system cmd etc didn’t help.
  5. Type mingw-get into the command line.
  6. After type mingw-get install mingw32-make.

Done! Now You might be able to use make-commands from any folder that contains Makefile.

Ashish Kankal's user avatar

answered Jan 25, 2021 at 16:53

binary robot's user avatar

0

With Visual Studio 2017 I had to add this folder to my Windows 10 path env variable:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\bin\HostX64\x64

There’s also HostX86

answered Apr 24, 2017 at 13:01

Jón Trausti Arason's user avatar

If it is a «NMake Makefile», that is to say the syntax and command is compatible with NMake, it will work natively on Windows. Usually Makefile.win (the .win suffix) indicates it’s a makefile compatible with Windows NMake. So you could try nmake -f Makefile.win.

Often standard Linux Makefiles are provided and NMake looks promising. However, the following link takes a simple Linux Makefile and explains some fundamental issues that one may encounter. It also suggests a few alternatives to handling Linux Makefiles on Windows.

Makefiles in Windows

answered Dec 2, 2015 at 6:00

ap-osd's user avatar

ap-osdap-osd

2,64416 silver badges16 bronze badges

Firstly, add path of visual studio common tools (c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools) into the system path. To learn how to add a path into system path, please check this website:
http://www.computerhope.com/issues/ch000549.htm. You just need to this once.

After that, whenever you need, open a command line and execute vsvars32.bat to add all required visual studio tools’ paths into the system path.

Then, you can call nmake -f makefile.mak

PS: Path of visual studio common tools might be different in your system. Please change it accordingly.

answered Oct 26, 2015 at 13:59

Validus Oculus's user avatar

Validus OculusValidus Oculus

2,7861 gold badge25 silver badges35 bronze badges

If you have already installed the Windows GNU compiler (MinGW) from MSYS2 then make command comes pre-installed as wingw32-make. Always match cmake makefile generation with the correct make command. Mixing these generate problems.

MinGW makefile generation with MinGW make command

Visual Studio makefile generation with VS equivalent make command

And this is always possible as long as you have the source code. Just delete old build directory and start over by specifying this time the right parameter in cmake ,e.g.

mkdir build
cd build
cmake -G "MinGW MakeFiles" path/to/src/whereCMakeLists.txtInstructionsAre   
mingw32-make     
myProject.exe   # RUN

I have encountered issues during compilation where multiple make commands interact. To prevent this just edit/remove the environmental variables that lead to different make commands. For example to prevent conflicts with mingw, keep only C:\msys64\mingw64\bin but remove C:\msys64\usr\bin. That other path contains the msys make and as I said you do not want to combine make commands during compilation.

answered Jun 14, 2022 at 5:09

Bryan Laygond's user avatar

Install msys2 with make dependency add both to PATH variable.
(The second option is GNU ToolChain for Windows. MinGW version has already mingw32-make included.)

Install Git Bash. Run mingw32-make from Git Bash.

answered Feb 10, 2021 at 16:17

Liam Kernighan's user avatar

Liam KernighanLiam Kernighan

2,3551 gold badge21 silver badges24 bronze badges

1

So if you’re using Vscode and Mingw then you should first make sure that the bin folder of the mingw is included in the environment path and it is preferred to change the mingw32-make.exe to make to ease the task and then create a makefile
and include this code in it .

all:
    gcc -o filename filename.c
    ./filename

Then save the makefile and open Vscode Code terminal and write make. Then makefile will get executed.

answered Dec 30, 2020 at 14:11

Lovish Garg's user avatar

1

I am assuming you added mingw32/bin is added to environment variables else please add it and I am assuming it as gcc compiler and you have mingw installer.

First step: download mingw32-make.exe from mingw installer, or please check mingw/bin folder first whether mingw32-make.exe exists or not, else than install it, rename it to make.exe.

After renaming it to make.exe, just go and run this command in the directory where makefile is located. Instead of renaming it you can directly run it as mingw32-make.

After all, a command is just exe file or a software, we use its name to execute the software, we call it as command.

Anatoly's user avatar

Anatoly

21k3 gold badges29 silver badges42 bronze badges

answered Dec 3, 2020 at 16:13

Bheem's user avatar

BheemBheem

212 bronze badges

For me installing ubuntu WSL on windows was the best option, that is the best tool for compiling makefile on windows. One thousand is better than Cygwin64, because to compile a makefile you will need another package and compile software like maybe gfortran, netcdf, etc, ect, in ubuntu WSL you can install all of these packages very easily and quickly ;)

answered Oct 14, 2022 at 15:16

mapiedrahitao's user avatar

1

The procedure I followed is;

  1. I installed Gnuwin32’s make using the installable.
  2. Added the «make» path to the environmental variable PATH.
  3. Verified the installation using «make —version»

answered Nov 10, 2022 at 11:57

Bhuvan's user avatar

BhuvanBhuvan

3709 bronze badges

1

You can also install via the Scoop package manager (similar to Chololatey). Go to Scoop and search for the package you need. In this case make and paste the command for installing it.

Command to install make on Windows. I tested in PowerShell.

scoop install main/make

tripleee's user avatar

tripleee

176k34 gold badges275 silver badges318 bronze badges

answered Jun 7 at 17:26

Felipe Illanes's user avatar

May be it can work.

pip install Makefile

answered Jun 10, 2021 at 11:22

Nikhil Parashar's user avatar

I have some demos that I downloaded and they come with a Makefile.win and a Makefile.sgi. How can I run these in Windows to compile the demos?

0x6B6F77616C74's user avatar

asked Mar 28, 2010 at 7:48

Kim's user avatar

8

You can install GNU make with chocolatey, a well-maintained package manager, which will add make to the global path and runs on all CLIs (powershell, git bash, cmd, etc…) saving you a ton of time in both maintenance and initial setup to get make running.

  1. Install the chocolatey package manager for Windows
    compatible to Windows 7+ / Windows Server 2003+

  2. Run choco install make

I am not affiliated with choco, but I highly recommend it, so far it has never let me down and I do have a talent for breaking software unintentionally.

answered Jul 15, 2019 at 15:05

ledawg's user avatar

ledawgledawg

2,4151 gold badge11 silver badges17 bronze badges

2

If you have Visual Studio, run the Visual Studio Command prompt from the Start menu, change to the directory containing Makefile.win and type this:

nmake -f Makefile.win

You can also use the normal command prompt and run vsvars32.bat (c:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools for VS2008). This will set up the environment to run nmake and find the compiler tools.

answered Mar 28, 2010 at 7:50

Marcelo Cantos's user avatar

Marcelo CantosMarcelo Cantos

181k38 gold badges328 silver badges365 bronze badges

16

Check out GnuWin’s make (for windows), which provides a native port for Windows (without requiring a full runtime environment like Cygwin)

If you have winget, you can install via the CLI like this:

winget install GnuWin32.Make

Also, be sure to add the install path to your system PATH:

C:\Program Files (x86)\GnuWin32\bin

KyleMit's user avatar

KyleMit

30.6k67 gold badges463 silver badges666 bronze badges

answered Jun 6, 2013 at 13:41

Sean Lynch's user avatar

Sean LynchSean Lynch

6,2872 gold badges43 silver badges45 bronze badges

3

Check out cygwin, a Unix alike environment for Windows

answered Mar 28, 2010 at 7:50

Frank's user avatar

FrankFrank

2,3731 gold badge19 silver badges17 bronze badges

4

Here is my quick and temporary way to run a Makefile

  • download make from SourceForge: gnuwin32
  • install it
  • go to the install folder

C:\Program Files (x86)\GnuWin32\bin

  • copy the all files in the bin to the folder that contains Makefile

libiconv2.dll libintl3.dll make.exe

  • open the cmd (you can do it with right click with shift) in the folder that contains Makefile and run

make.exe

done.

Plus, you can add arguments after the command, such as

make.exe skel

Maria Ines Parnisari's user avatar

answered Oct 20, 2017 at 3:59

alan9uo's user avatar

alan9uoalan9uo

1,0211 gold badge11 silver badges17 bronze badges

4

If you install Cygwin. Make sure to select make in the installer. You can then run the following command provided you have a Makefile.

make -f Makefile

https://cygwin.com/install.html

answered Feb 14, 2019 at 1:24

sunny0402's user avatar

sunny0402sunny0402

911 silver badge2 bronze badges

I use MinGW tool set which provides mingw32-make build tool, if you have it in your PATH system variables, in Windows Command Prompt just go into the directory containing the files and type this command:

mingw32-make -f Makefile.win

and it’s done.

answered Jun 27, 2020 at 15:55

WENDYN's user avatar

WENDYNWENDYN

6707 silver badges15 bronze badges

1

I tried all of the above. What helps me:

  1. Download the mingw-get.
  2. Setup it.
  3. Add something like this C:\MinGW\bin to environment variables.
  4. Launch (!important) git bash. Power shell, developer vs cmd, system cmd etc didn’t help.
  5. Type mingw-get into the command line.
  6. After type mingw-get install mingw32-make.

Done! Now You might be able to use make-commands from any folder that contains Makefile.

Ashish Kankal's user avatar

answered Jan 25, 2021 at 16:53

binary robot's user avatar

0

With Visual Studio 2017 I had to add this folder to my Windows 10 path env variable:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\bin\HostX64\x64

There’s also HostX86

answered Apr 24, 2017 at 13:01

Jón Trausti Arason's user avatar

If it is a «NMake Makefile», that is to say the syntax and command is compatible with NMake, it will work natively on Windows. Usually Makefile.win (the .win suffix) indicates it’s a makefile compatible with Windows NMake. So you could try nmake -f Makefile.win.

Often standard Linux Makefiles are provided and NMake looks promising. However, the following link takes a simple Linux Makefile and explains some fundamental issues that one may encounter. It also suggests a few alternatives to handling Linux Makefiles on Windows.

Makefiles in Windows

answered Dec 2, 2015 at 6:00

ap-osd's user avatar

ap-osdap-osd

2,64416 silver badges16 bronze badges

Firstly, add path of visual studio common tools (c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools) into the system path. To learn how to add a path into system path, please check this website:
http://www.computerhope.com/issues/ch000549.htm. You just need to this once.

After that, whenever you need, open a command line and execute vsvars32.bat to add all required visual studio tools’ paths into the system path.

Then, you can call nmake -f makefile.mak

PS: Path of visual studio common tools might be different in your system. Please change it accordingly.

answered Oct 26, 2015 at 13:59

Validus Oculus's user avatar

Validus OculusValidus Oculus

2,7861 gold badge25 silver badges35 bronze badges

If you have already installed the Windows GNU compiler (MinGW) from MSYS2 then make command comes pre-installed as wingw32-make. Always match cmake makefile generation with the correct make command. Mixing these generate problems.

MinGW makefile generation with MinGW make command

Visual Studio makefile generation with VS equivalent make command

And this is always possible as long as you have the source code. Just delete old build directory and start over by specifying this time the right parameter in cmake ,e.g.

mkdir build
cd build
cmake -G "MinGW MakeFiles" path/to/src/whereCMakeLists.txtInstructionsAre   
mingw32-make     
myProject.exe   # RUN

I have encountered issues during compilation where multiple make commands interact. To prevent this just edit/remove the environmental variables that lead to different make commands. For example to prevent conflicts with mingw, keep only C:\msys64\mingw64\bin but remove C:\msys64\usr\bin. That other path contains the msys make and as I said you do not want to combine make commands during compilation.

answered Jun 14, 2022 at 5:09

Bryan Laygond's user avatar

Install msys2 with make dependency add both to PATH variable.
(The second option is GNU ToolChain for Windows. MinGW version has already mingw32-make included.)

Install Git Bash. Run mingw32-make from Git Bash.

answered Feb 10, 2021 at 16:17

Liam Kernighan's user avatar

Liam KernighanLiam Kernighan

2,3551 gold badge21 silver badges24 bronze badges

1

So if you’re using Vscode and Mingw then you should first make sure that the bin folder of the mingw is included in the environment path and it is preferred to change the mingw32-make.exe to make to ease the task and then create a makefile
and include this code in it .

all:
    gcc -o filename filename.c
    ./filename

Then save the makefile and open Vscode Code terminal and write make. Then makefile will get executed.

answered Dec 30, 2020 at 14:11

Lovish Garg's user avatar

1

I am assuming you added mingw32/bin is added to environment variables else please add it and I am assuming it as gcc compiler and you have mingw installer.

First step: download mingw32-make.exe from mingw installer, or please check mingw/bin folder first whether mingw32-make.exe exists or not, else than install it, rename it to make.exe.

After renaming it to make.exe, just go and run this command in the directory where makefile is located. Instead of renaming it you can directly run it as mingw32-make.

After all, a command is just exe file or a software, we use its name to execute the software, we call it as command.

Anatoly's user avatar

Anatoly

21k3 gold badges29 silver badges42 bronze badges

answered Dec 3, 2020 at 16:13

Bheem's user avatar

BheemBheem

212 bronze badges

For me installing ubuntu WSL on windows was the best option, that is the best tool for compiling makefile on windows. One thousand is better than Cygwin64, because to compile a makefile you will need another package and compile software like maybe gfortran, netcdf, etc, ect, in ubuntu WSL you can install all of these packages very easily and quickly ;)

answered Oct 14, 2022 at 15:16

mapiedrahitao's user avatar

1

The procedure I followed is;

  1. I installed Gnuwin32’s make using the installable.
  2. Added the «make» path to the environmental variable PATH.
  3. Verified the installation using «make —version»

answered Nov 10, 2022 at 11:57

Bhuvan's user avatar

BhuvanBhuvan

3709 bronze badges

1

You can also install via the Scoop package manager (similar to Chololatey). Go to Scoop and search for the package you need. In this case make and paste the command for installing it.

Command to install make on Windows. I tested in PowerShell.

scoop install main/make

tripleee's user avatar

tripleee

176k34 gold badges275 silver badges318 bronze badges

answered Jun 7 at 17:26

Felipe Illanes's user avatar

May be it can work.

pip install Makefile

answered Jun 10, 2021 at 11:22

Nikhil Parashar's user avatar

We’re Earthly. We make building software simpler and therefore faster. This article is about make and Makefiles but if you’re interested in a different approach to building software then check us out.

As the field of DevOps and build release engineering continues to grow, many new tools are being developed to help make building and releasing applications easier. One of the tools that has been in use for many years is Make, which is still heavily used by engineers today.

A Makefile is a simple text file consisting of targets, which can invoke different actions depending on what has been configured. For example, with a Makefile, you can invoke a build of your application, deploy it, or run automated tests and it can dramatically increase the efficiency of your workflow.

Initially, it was Stuart Feldman who began working on the Make utility back in 1976 at Bell Labs. However, the version of Make most commonly used today is GNU Make, which was introduced in the late 1980s.

While the tool was originally meant to run on Linux, Make’s popularity has interested those working on other operating systems as well. There are several ways to run Makefiles on Windows, and in this article you’ll be introduced to each option and learn about their strengths and weaknesses.

Using Make on Windows

windows

Before looking at the different options available, you should know why you want to run Makefiles on Windows in the first place. Or rather, if you’re working on Windows, why are you even interested in Makefiles?

Historically, the biggest reason for wanting Makefiles to run on Windows is that the developers in your organization are working on Windows. Seeing as how the de facto standard for languages like C and C++ is to use Make, it’s no wonder that Windows users want the ability to use Make as well.

As applications and infrastructure become more modern, the cloud is another reason for wanting Makefiles on Windows. Many infrastructure engineers want their applications to be run on Linux, likely led by the adoption of tools like Docker and containerization in general. Additionally, on Linux, a Makefile is the primary tool to use in many cases, especially when it comes to building native Linux applications. However, many engineers are still using Windows on their workstations, leading to the question of how to run Makefiles on Windows. Let’s dive into the possible answers.

Chocolatey

chocolatey

Linux users have been using package managers for decades, yet they’ve never gained much traction on Windows. Up until the release of winget, the concept of a package manager was never something that was natively included on Windows. Instead, Rob Reynolds started working on an independent package manager back in 2011 that would come to be known as Chocolatey. Chocolatey is now widely used on Windows to install packages, and you can use it to install make as well.

To do so, run the following command in an Administrative PowerShell window:

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

You can find the newest installation instructions at any time on the Chocolatey website.

Once Chocolatey is installed, you may have to close down the PowerShell window and open it back up. After that, run the following command:

Once the script is done running, make will be installed. You may need to restart the PowerShell window again, but at this point you are ready to use Makefiles on Windows.

Chocolatey will likely be the most popular option for those who want to stick to a pure Windows installation. It’s easy to install, easy to use, and you don’t need to jump through any hoops or workarounds to get it working.

At this point, you can use make just like you otherwise would, and you can test it by running make -v.

Cygwin

Historically, one of the most popular ways of running any type of Linux functionality on Windows has been to use Cygwin. Cygwin aims to give a Linux feeling to Windows by holding a large collection of GNU and open source tools. It’s important to note that this does not mean it will give you native Linux functionality. However, it does allow you to use Linux tools on Windows. There’s a big difference between the two; for instance, Cygwin does not have access to Unix functionality like signals, PTYs, and so on. It’s a great tool for when you want to use familiar Linux commands but still want them to be run on Windows.

To use Cygwin for Makefiles, start by downloading and installing Cygwin. During the installation, you’ll see a window popping up asking you what packages you want to install. In the top left corner, make sure to select Full and then search for make.

Searching for “make”

Your search will give you a list of several different packages. You want to choose the one that’s labeled just as make. Change the dropdown menu where it says Skip to the latest version.

Choosing “make”

Now you can finish the installation by clicking Next in the bottom right corner. Once the installation is done, you can open up Cygwin and verify that make has been installed by executing make --version.

NMAKE

One of the alternatives that you’ll often hear about regarding running Makefiles on Windows is NMAKE. While it is an alternative to make, note that you cannot simply take your existing Makefiles from Linux and run them using NMAKE; they have to be ported.

First of all, the compilers are different on Windows and Linux, so if you are specifying your compiler in your Makefile, you’ll have to change that to whatever is relevant on Windows. At the same time, you’ll have to change the flags that you send to the compiler, because Windows typically denotes the flags using / instead of -.

On top of that, it doesn’t recognize all the syntax that you’re used to from GNU Make, like .PHONY. Lastly, Windows obviously doesn’t recognize the commands that work on Linux, so if you have specified any Linux-specific commands in your Makefiles, you’ll also have to port them.

All in all, if your entire organization uses Windows and you simply want the typical functionality of GNU Make, then NMAKE is a viable solution. However, if you just want to quickly run your traditional Makefiles on Windows, NMAKE is not the answer.

CMake

cmake

As with NMAKE, CMake is not a direct way to run your Makefiles on Windows. Instead, CMake is a tool to generate Makefiles, at least on Linux. It works by defining a CMakeLists.txt file in the root directory of your application. Once you execute cmake, it generates the files you need to build your application, no matter what operating system you’re on.

On Linux, this means that it creates Makefiles for you to run, but on Windows it may mean that it creates a Visual Studio solution.

CMake is a great solution if you don’t care too much about running Makefiles specifically, but you want the functionality, namely the ease of use in a build process, that you can get from Makefiles.

Windows Subsystem for Linux

The Windows Subsystem for Linux (WSL) is an honorable mention. It’s cheating a bit to say that it’s a way to run Makefiles “on Windows,” as your Makefiles won’t actually be running on Windows.

If you haven’t heard of WSL before, here’s an extremely oversimplified explanation: It uses Hyper-V to create a hyper-optimized virtual machine on your computer, in which it runs Linux. Basically, you get a native Linux kernel running on your Windows computer, with a terminal that feels as if it’s part of Windows.

You should look into WSL if what you care about most is having Windows as your regular desktop environment, but you’re fine with all of your programming and development going on inside of Linux.

Conclusion

As you can see, there are a few different ways you can be successful in running Makefiles on Windows. However, you do need to be wary of the fact that it will never be a perfect solution. Every solution is in some way a workaround, and the closest you’ll get to feeling like you’re using native Makefiles while using Windows is to install something like WSL.

If you are looking for a solution to avoid the complexities of Makefile, check out Earthly. Earthly takes the best ideas from Makefile and Dockerfile, and provides understandable and repeatable build scripts, minus the head-scratching parts of the Makefile.

A makefile is a commonly used tool for managing software builds in Unix-based systems, but what if you need to build the software in a Windows environment? The Windows Command Prompt does not have native support for makefiles, so you need to use an alternative approach to run the makefile in Windows. Here are a few methods you can use to run a makefile in Windows:

Method 1: Using MinGW and MSYS

To run a makefile in Windows using MinGW and MSYS, you can follow these steps:

  1. Install MinGW and MSYS on your Windows machine.

  2. Open MSYS terminal and navigate to the directory where your makefile is located.

  3. Run the following command to generate the makefile:

  4. Once the makefile is generated, you can run the following command to compile your code:

    This will compile all the source files and generate the executable file.

  5. If you want to clean up the generated files, you can run the following command:

    This will remove all the object files and the executable file.

Here is an example makefile that compiles a C program:

CC=gcc
CFLAGS=-Wall

all: myprogram.exe

myprogram.exe: main.o utils.o
    $(CC) $(CFLAGS) -o myprogram.exe main.o utils.o

main.o: main.c
    $(CC) $(CFLAGS) -c main.c

utils.o: utils.c
    $(CC) $(CFLAGS) -c utils.c

clean:
    rm -f *.o myprogram.exe

In this makefile, we have defined the compiler (gcc) and the compiler flags (-Wall). We have also defined the targets (all, myprogram.exe, main.o, utils.o) and the dependencies. The commands to compile the source files and generate the executable file are specified under each target.

By following these steps and using this example makefile, you should be able to run your makefile in Windows using MinGW and MSYS.

Method 2: Using Cygwin

To run a makefile in Windows using Cygwin, you need to follow these steps:

  1. Install Cygwin on your Windows machine. You can download the setup file from the official website and follow the installation instructions.

  2. Open the Cygwin terminal and navigate to the directory where your makefile is located using the cd command. For example, if your makefile is in the C:\Projects\MyProject directory, you can navigate to it by typing cd /cygdrive/c/Projects/MyProject in the Cygwin terminal.

  3. Once you are in the directory containing the makefile, you can run the makefile by typing make in the Cygwin terminal. This will execute the default target in the makefile.

  4. If you want to execute a specific target in the makefile, you can specify it by typing make target_name. For example, if you want to execute the clean target in the makefile, you can type make clean.

Here is an example of a simple makefile that compiles a C program:

CC=gcc
CFLAGS=-Wall -Wextra

all: program

program: main.o
    $(CC) $(CFLAGS) -o program main.o

main.o: main.c
    $(CC) $(CFLAGS) -c main.c

clean:
    rm -f program main.o

In this makefile, the all target is the default target, which depends on the program target. The program target depends on the main.o target, which compiles the main.c file into an object file. Finally, the clean target removes the compiled program and object files.

To run this makefile using Cygwin, you can follow these steps:

  1. Save the above makefile as Makefile in a directory on your Windows machine.

  2. Open the Cygwin terminal and navigate to the directory where the makefile is located using the cd command.

  3. Type make in the Cygwin terminal to compile the program.

  4. Type ./program in the Cygwin terminal to run the compiled program.

  5. Type make clean in the Cygwin terminal to remove the compiled program and object files.

That’s it! You have successfully run a makefile in Windows using Cygwin.

Method 3: Using Visual Studio Command Prompt

To run a makefile in Windows using Visual Studio Command Prompt, follow these steps:

  1. Open Visual Studio Command Prompt by searching for it in the Start menu.

  2. Navigate to the directory containing the makefile using the cd command.

  3. Type nmake followed by the target you want to build. For example, if your makefile has a target named all, you would type nmake all.

Here is an example makefile:

CC = gcc
CFLAGS = -Wall -Werror

all: hello.exe

hello.exe: hello.o
    $(CC) $(CFLAGS) -o hello.exe hello.o

hello.o: hello.c
    $(CC) $(CFLAGS) -c hello.c

clean:
    del *.o *.exe

In this makefile, the CC variable specifies the compiler to use, and the CFLAGS variable specifies the compiler flags. The all target depends on the hello.exe target, which in turn depends on the hello.o target. The clean target removes the object files and executable.

To build the hello.exe target using Visual Studio Command Prompt, follow these steps:

  1. Open Visual Studio Command Prompt.

  2. Navigate to the directory containing the makefile using the cd command.

  3. Type nmake hello.exe to build the hello.exe target.

  4. Type hello to run the executable.

  5. Type nmake clean to remove the object files and executable.

That’s it! With these steps, you can run a makefile in Windows using Visual Studio Command Prompt.

Method 4: Using WSL (Windows Subsystem for Linux)

To run a makefile in Windows using WSL (Windows Subsystem for Linux), follow these steps:

  1. Open the WSL terminal by typing «wsl» in the Windows search bar and selecting the «Ubuntu» app.

  2. Navigate to the directory containing the makefile using the «cd» command.

  3. Run the make command followed by the name of the makefile.

    If the makefile has a different name, replace «Makefile» with the actual name of the makefile.

  4. If the makefile requires any dependencies, install them using the appropriate package manager for your Linux distribution. For example, to install the «build-essential» package on Ubuntu, run the following command:

    sudo apt-get install build-essential
  5. If the makefile produces any output files, make sure to specify the correct path for the output files in the makefile. For example, if the makefile generates an executable file called «myprogram», make sure the output path is set to a directory that is accessible from Windows.

    all: myprogram
    
    myprogram: main.c
        gcc -o /mnt/c/Users/username/Desktop/myprogram main.c

    In this example, the executable file «myprogram» is saved to the Windows desktop using the «/mnt/c» mount point.

That’s it! You should now be able to run the makefile in Windows using WSL.

Makefile — это специальный файл, содержащий информацию, связанную с потоком программы, целями и библиотеками. Его также называют файлом описания. Makefile содержит группу целей и источников, от которых они зависят. Makefile также содержит библиотеки, поддерживающие исходный код. Этот тип файла выполняется с помощью команды make.

В этой статье будет рассмотрен метод установки и запуска Makefile в Windows.

Как установить команду make в Windows?

Чтобы запустить Makefile в Windows, сначала необходимо установить инструмент командной строки make. Для этого выполните перечисленные ниже шаги в вашей системе Windows.

Шаг 1: Установите диспетчер пакетов MinGW

Чтобы установить утилиту make, сначала загрузите менеджер пакетов MinGW. Для этого перейдите по приведенной ниже ссылке и выберите пакет, который хотите установить:

https://osdn.net/проекты/мингв/выпускает/

Нажми на «Установить», чтобы начать установку MinGW:

Укажите место, где вы хотите установить менеджер пакетов MinGW, снимите флажок с опции установки графического пользовательского интерфейса и нажмите «Продолжать» кнопка:

После успешной установки менеджера пакетов MinGW нажмите «Покидать» кнопка:

Шаг 2: Установите переменные среды

На следующем шаге перейдите в «С» диск, открыть «МинГВт» и найдите папку «mingw-get.exe» файл. Скопируйте расположение файла, как показано ниже:

Ищи «Переменные среды» в «Запускать” и откройте его:

Нажми на «Переменные среды», чтобы установить путь в переменных окружения:

От «Системные переменные», выберите данный «Дорожка«, и нажмите на кнопку «Редактировать» кнопка:

После этого нажмите кнопку «Новый” и вставьте скопированный путь в поле Путь. Затем нажмите «Ok» кнопка:

Шаг 4: Установите команду make

Сначала найдите «CMD» в «Запускать» и откройте командную строку:

Затем выполните приведенную ниже команду, чтобы установить make в Windows:

>mingw-получить установить mingw32-сделать

Шаг 5: Подтвердите установку

Проверьте установку команды make, проверив ее версию:

>mingw32-сделать —версия

Мы успешно установили GNU Make».3.82.90” в Windows:

Вы можете видеть, что мы используем «mingw32-сделать” вместо “делать”. Давайте двигаться вперед, чтобы исправить это.

Шаг 6: Переименуйте файл mingw32-make.exe

Перейти к «С» и откройте папку «МинГВт» папка:

После этого откройте «мусорное ведро» и найдите папку «mingw32-make.exe» файл:

Переименуйте имя файла как «make.exe”:

Теперь проверьте версию с помощью команды make:

>делать—версия

До этого момента мы установили и настроили make в Windows. Давайте двигаться дальше, чтобы создать новый Makefile.

Как создать Makefile в Windows?

Выполните следующие шаги, чтобы создать простой запрограммированный Makefile в Windows.

Шаг 1: Создайте новую папку

Сначала создайте новую папку, как мы создали «Первый проект» на рабочем столе:

Шаг 2: Создайте MakeFile

Откройте только что созданную папку и создайте простой текстовый файл с именем «Makefile”:

Вставьте приведенный ниже код в Makefile и нажмите «CTRL+S», чтобы сохранить изменения:

первый makefile:
эхо«Это мой первый Makefile»;

Шаг 3. Удалите расширение .txt

Щелкните правой кнопкой мыши Makefile и выберите «Переименовать” из данного варианта и удалите “.текст» расширение. Не меняйте имя файла; удалить только «.текст» расширение:

А “Переименовать” для подтверждения на экране отобразится окно предупреждающего сообщения. Ударь «Да» кнопка:

Вот и все! Makefile создан и готов к выполнению:

Давайте перейдем к способу запуска Makefile в Windows.

Как запустить Makefile в Windows?

Следуйте приведенным ниже инструкциям, чтобы запустить Makefile в Windows.

В «Запускатьменю, найдите «CMD» и запустите командную строку от имени администратора:

Использовать «CD” вместе с путем Makefile, чтобы перейти в этот конкретный каталог. Затем используйте «делать” для запуска созданного Makefile в Windows:

>CD C:\Users\Талья Саиф\Desktop\Firstproject
>делать

Предоставленная команда make выполнит Makefile и отобразит вывод в командной строке:

Вы также можете использовать функцию «-f” для чтения любого файла как Makefile:

>делать-fфайл

Мы эффективно продемонстрировали метод установки команды make и запуска Makefile в Windows.

Вывод

Перед запуском Makefile в Windows необходимо сначала установить команду make, используя «Mingw-получить установку mingw32-сделать” в командной строке. Затем создайте Makefile, удалите «.текст«, и используйте расширение «делать” для запуска указанного файла Makefile в Windows. Мы продемонстрировали способ установки команды make и создание и запуск файла Makefile в Windows.

  • Как запустить msconfig на windows 10
  • Как запустить make в windows 10
  • Как запустить google play на windows 11
  • Как запустить mount and blade история героя на windows 10
  • Как запустить mac os на virtualbox на windows