相同的命令行中制作产生错误但如果从shell中运行成功 [英] Exact same command line produces error in Make yet succeeds if run from shell

查看:109
本文介绍了相同的命令行中制作产生错误但如果从shell中运行成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我只是不能绕到我的头一个问题。我有一个应该编译一个非常简单的.c文件成可执行程序小例子生成文件。

I have a problem that I just can't wrap my head around. I have a minimal example makefile that is supposed to compile a very simple .c file into an executable program.

当我运行的使,编译器编译开始,然后产生一个错误消息

When I run make, the compiler starts compiling and then produces an error message

T:\\ printOffsets.c:10:21:错误:bootIfc.h:没有这样的文件或
  目录

"T:\printOffsets.c:10:21: error: bootIfc.h: No such file or directory"

然后我复制完全相同的命令行所构建目标,并直接在同一个Windows命令shell实例中运行它,突然编译成功没有错误!该命令行(路径名简体):

Then I copy the exact same command line make is using to build the target and run it directly in the same Windows command shell instance, and suddenly compilation succeeds without errors!! The command line is (path names simplified):

T:\\ perl的\\ C \\ BIN \\ gcc.exe T:\\ printOffsets.c -IT:\\包括\\ -o
  D:\\ printOffsets.exe

T:\perl\c\bin\gcc.exe T:\printOffsets.c -IT:\include\ -o D:\printOffsets.exe

我怎么知道?好吧,打印命令行执行它之前,所以我干脆复制和放大器;从壳粘贴

How do I know? Well, make prints the command line before it executes it, so I simply copy&paste from the shell.

我不明白这一点!这怎么可能??怎样才能当一个Makefile ??

I don't get it! How is this possible?? How can the exact same command work on the shell and fail if launched from within a Makefile??

我使用GNU使3.82在Windows 7上,顺便说一句。

I'm using GNU Make 3.82 on Windows 7, by the way.

推荐答案

在生成文件中的命令是给从外壳不同的结果,只是要确保它正在使用您想要的外壳。

When command in makefile is giving different result from shell, just make sure it is using the shell you want.

添加假目标在你的make文件:

Add a phony target in your make file:

.PHONY:testshell

testshell:
    echo $(SHELL)

和运行:

gmake testshell

如果结果是不是你最喜欢的外壳可以通过添加一行迫使它像这样在你的makefile的开头:

If the result is not your favorite shell you can force it by adding a line such as this one at the beginning of your makefile:

SHELL=C:\Windows\System32\cmd.exe

如果你不能确定你的shell的完整路径,只需打开一个DOS控制台和启动:

If you are not sure of full path of your shell, just open a DOS console and launch:

where cmd

编辑:替代的解决方案。

alternative solution

在使用 SH 的外壳,而不是 CMD 的外壳,也可以替换命令所有的反斜线与斜线和保持使用 SH

When using sh shell instead of cmd shell, you can also replaces all backslashes in commands with slashes and keep using sh.

编辑2:改变单一目标壳

这篇关于相同的命令行中制作产生错误但如果从shell中运行成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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