Windows Makefile中的反斜杠 [英] Backslashes in Windows makefiles

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

问题描述

重要此后,我已经解决了特定Makefile的问题,但我不知道如何解决.

Important edit: I've since solved the problem with my specific makefile, but I don't know how.

我用反斜杠替换了反斜杠,结果证明我的规则可以正常使用.Gcc接受正斜杠和反斜杠的混合,因此效果很好. mkdir 存在一个棘手的问题:它不接受带有正斜杠和反斜杠混合的路径.我将变量更改为仅在Windows版本中包含反斜杠,现在文件可以正常工作了.

I replaced backslashes with forward slashes and it turns out my rules work fine with those. Gcc accepts mixed forward and back slashes, so it worked fine. A sticking point existed with mkdir: it doesn't accept paths with mixed forward and back slashes. I changed my variables to include only back slashes in the Windows version, and now the file works perfectly.

作为参考,这里有一些新的规则和变量:

For reference, here's some new rules and variables:

OUT = $(ROOT)\ outSRC = $(根)\ src$(OUT):mkdir $ {OUT)$(OUT)/%.o:$(SRC)/%.c$(CC)$(CFLAGS)-o $ @ -c $<

为什么minGW-make在变量扩展后为什么接受规则中的混合斜杠而不是仅反斜杠?到底是怎么回事?

Why does minGW-make accept mixed slashes in rules after variable expansion but not backslashes-only? What exactly is going here?

我为Windows安装了make的minGW.我复制了我的unix makefile,并将命令转换为Windows(将正斜杠转换为反斜杠),但是生成的makefile不起作用.

I have a minGW install of make for windows. I copied my unix makefile and converted the commands to windows (and forward slashes to backslashes) but the resulting makefile does not work.

主要区别在于Windows具有 $(OUT)= $(ROOT)\ out \ win ,而Unix具有 $(OUT)= $(ROOT)/out .Unix可以正常工作.Windows上的 make -f makefile.win 抱怨< root> \ out \ win \ LinkedList.o 没有规则.有问题的规则和错误是:

The main difference is that Windows has $(OUT) = $(ROOT)\out\win and Unix has $(OUT) = $(ROOT)/out. Unix works fine. make -f makefile.win on windows complains that there is no rule for <root>\out\win\LinkedList.o. The rules and error in question are:

make:***没有规则可以使目标H:\ CodeRIT \ 1014Syllables \ out \ win \ LinkedList.o'所需.EXE文件'.停止.

<代码> $(OUT)\%.o:$(ROOT)\ src \%.cgcc $(CFLAGS)-o $ @ -c $<

<代码> $(OUT)\ bin \ syllables.exe:$(OUT)\ LinkedList.o $(OUT)\ Syllable.o $(OUT)\ Model.ogcc $(CFLAGS)-o $ @ $ ^

$(OUT)应该扩展为< root> \ out \ win ,从而给出它抱怨目标明确的文件.我不明白为什么该规则不起作用,因为相同的规则在Unix上也可以正常工作.是否有一些关于目标中最大目录的神秘规则?我没有足够的make经验来真正评估这里出了什么问题.

$(OUT) should expand to <root>\out\win giving the file it complains about a clear target. I don't understand why this rule doesn't work, given that the same rule works just fine on Unix. Is there some arcane rule about maximum directories in targets or something? I don't have enough experience with make to really assess what's going wrong here.

这是相关文件的全文: https://github.com/blastedt/syllables/blob/master/makefile.win

Here's the full text of the file in question: https://github.com/blastedt/syllables/blob/master/makefile.win

推荐答案

$(OUT)\%.o:没有定义模式规则,您

$(OUT)\%.o: does not define a pattern rule, you've escaped the %.

$(OUT)\\%.o:应该可以工作,尽管是因为这样的陷阱,所以在Windows上使用make时最好避免反斜杠.

$(OUT)\\%.o: should work in this case, although it's because of gotchas like this that it's best to avoid backslashes when using make on Windows.

您将遇到诸如 mkdir del 之类的shell命令无法使用正斜杠的问题,您应该考虑切换到powershell,cygwin,MSYS2或在Windows上重击.

You will run into issues with shell commands like mkdir and del not working with forward slashes, you should consider switching to powershell, cygwin, MSYS2, or bash on windows.

这篇关于Windows Makefile中的反斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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