C++ 在 Windows 上使用 Makefile 编译

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

Compile using Makefile on Windows

c++cwindows

提问by vinay patel

I want to compile my code using MakeFile in a Windows environment. I have created a Makefile in Linux but don't have any idea how to create and run in Windows. I have installed MinGW and also edited the environment variable path. I have tried running the Makefile like I was doing in a Linux environment, but I'm not able to run it. Can anyone please share any link.

我想在 Windows 环境中使用 MakeFile 编译我的代码。我在 Linux 中创建了一个 Makefile,但不知道如何在 Windows 中创建和运行。我已经安装了 MinGW 并编辑了环境变量路径。我曾尝试像在 Linux 环境中一样运行 Makefile,但我无法运行它。任何人都可以分享任何链接。

This is my simple Makefile

这是我的简单 Makefile

CC = g++

all: Exe 

Exe : main.o Hello.o

    $(CC) -o Exe main.o Hello.o

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

Hello.o: Hello.cpp
    $(CC) -c Hello.cpp

clean:
    rm -rf *o main.o Hello.o

I am running it from the command prompt make MakeFileand every time it prompts with the message, makefile up to date. It is not doing anything, not even generating an executable.

我从命令提示符make MakeFile运行它,每次它提示消息时,makefile up to date。它没有做任何事情,甚至没有生成可执行文件。

回答by benjarobin

The syntax is almost the same. It's really depend if you added specific command (like using find, grep, ...).

语法几乎相同。这真的取决于您是否添加了特定命令(例如使用find, grep, ...)。

You should add the error reported by makecommand to your question. Without more information we cannot guess where is the problem

您应该将make命令报告的错误添加到您的问题中。没有更多信息,我们无法猜测问题出在哪里

Edit:I did not understand that you do not find the make command. The makecommand is sometime named mingw32-make.exe. It's really depend which version and type of MinGW you installed

编辑:我不明白您没有找到 make 命令。该make命令有时名为mingw32-make.exe. 这实际上取决于您安装的 MinGW 的版本和类型

Edit2:The command line to type is make(or mingw32-make.exe) and not make MakefileTake a look at the man of make

Edit2:要输入的命令行是make(or mingw32-make.exe) 而不是make Makefile看看 manmake

In the clean:section, do not use rm, this command does not exist on Windows

在该clean:部分中,不要使用rm,Windows 上不存在此命令

回答by Dhananjaya

Goto bin directory in MinGW and check whether you have a file named make.exe if you don't have it then rename mingw32-make.exe to make.exe
As I remember normally make.exe is named mingw32-make.exe in the MinGW distribution, I don't know why they do so, but renaming it to make.exe can solve the problem in most of the cases.

转到 MinGW 中的 bin 目录并检查是否有名为 make.exe 的文件,如果没有,则将 mingw32-make.exe 重命名为 make.exe
因为我记得通常 make.exe 在MinGW 发行版,我不知道他们为什么这样做,但是将其重命名为 make.exe 可以解决大多数情况下的问题。