C++ mingw make 文件指南 mingw32-make

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

guide to mingw make files mingw32-make

c++windowsmakefilemingw

提问by Hesam Qodsi

I'm a C++ programmer and have experience with GCC on Linux. I want to develop an application in Windows , so i need a full guide to mingw make files, variables and mingw32-make. Is there anybody who can introduce a resource for this?

我是一名 C++ 程序员,有在 Linux 上使用 GCC 的经验。我想在 Windows 中开发一个应用程序,所以我需要一个关于 mingw make 文件、变量和 mingw32-make 的完整指南。有没有人可以为此介绍资源?

回答by James Kanze

mingw32-makeis just a pre-built version of GNU make, so http://www.gnu.org/software/make/manual/should have all of the information you need.

mingw32-make只是 GNU make 的预构建版本,因此 http://www.gnu.org/software/make/manual/应该包含您需要的所有信息。

回答by nirvana-msu

The main difference I came across is that mingw32-makewill use windows PATH. So if you try to run it from git bash it won't behave quite like you expect it to (namely, it will invoke batscripts when you don't expect it to, and shims also don't quite work).

我遇到的主要区别是mingw32-make将使用 Windows PATH。因此,如果您尝试从 git bash 运行它,它的行为将不会像您期望的那样(即,它会bat在您不期望的情况下调用脚本,并且垫片也无法正常工作)。

Setting SHELL := /bin/bashor anything similar won't have any effect (which you can debug by running make -d), but you can still make it use bashinstead of shby setting SHELL := bash.exe. That's doesn't solve the windows PATH problem though.

设置SHELL := /bin/bash或类似的东西不会有任何效果(您可以通过运行调试make -d),但您仍然可以使用它bash而不是sh通过设置SHELL := bash.exe. 但这并不能解决 Windows PATH 问题。

What I did notice however is that if I additionally set .SHELLFLAGS := -euo pipefail -cthen it suddenly behaves properly in git bash, as if it starts using Unix-like paths (would be great if someone could confirm / explain why exactly).

然而,我注意到的是,如果我另外设置,.SHELLFLAGS := -euo pipefail -c它会突然在 git bash 中正常运行,就好像它开始使用类 Unix 路径一样(如果有人可以确认/解释确切原因,那就太好了)。

So I ended up with the following in my Makefile:

所以我最终得到了以下内容Makefile

ifeq ($(OS),Windows_NT)
    SHELL := bash.exe
else
    SHELL := /usr/bin/env bash
endif
.SHELLFLAGS := -eo pipefail -c

With that setup it appears to behave normally in git bash, just like on Linux.

通过这种设置,它在 git bash 中似乎表现正常,就像在 Linux 上一样。