在 Windows 上使用 Makefile 编译 [英] Compile using Makefile on Windows

查看:27
本文介绍了在 Windows 上使用 Makefile 编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这是我的简单 Makefile

This is my simple 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

我从命令提示符 ma​​ke MakeFile 运行它,每次它提示消息时,ma​​kefile 是最新的.它没有做任何事情,甚至没有生成可执行文件.

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

推荐答案

语法几乎相同.这真的取决于你是否添加了特定的命令(比如使用 findgrep、...).

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

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

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

我不明白您没有找到 make 命令.make 命令有时名为 mingw32-make.exe.这真的取决于你安装的 MinGW 的版本和类型

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

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

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

clean:部分,不要使用rm,这个命令在Windows上不存在

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

这篇关于在 Windows 上使用 Makefile 编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆