gcc“ -Werror:没有这样的文件”是指目标还是Werror用法?

时间:2018-07-15 17:06:21

标签: c makefile gnu-make

我正在尝试遵循本课程(https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-s096-effective-programming-in-c-and-c-january-iap-2014/getting-started/),并遇到一些编译问题。

建议使用下面的gcc,make和Makefile。

我不知道我收到的错误消息是否与C源代码中的某些内容有关(似乎不太可能),或者与我配置gcc选项的方式有关。

$ gcc-8 -v
Using built-in specs.
COLLECT_GCC=gcc-8
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/8.1.0/libexec/gcc/x86_64-apple-darwin17.5.0/8.1.0/lto-wrapper
Target: x86_64-apple-darwin17.5.0
Configured with: ../configure --build=x86_64-apple-darwin17.5.0 --prefix=/usr/local/Cellar/gcc/8.1.0 --libdir=/usr/local/Cellar/gcc/8.1.0/lib/gcc/8 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-8 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --enable-checking=release --with-pkgversion='Homebrew GCC 8.1.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-nls
Thread model: posix
gcc version 8.1.0 (Homebrew GCC 8.1.0)

$ gmake -v
GNU Make 4.2.1
Built for x86_64-apple-darwin17.0.0
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ cat Makefile
CC:=gcc-8
CFLAGS:=-O0 -g -std=c99 -Wall -Wextra -Wshadow -pedantic –Werror
CXXFLAGS:=-O0 -g -std=c++11 -Wall -Wextra -Wshadow -pedantic -Weffc++ -Werror

$ cat nothing.c
int main (void){
  return 0;
}

$ gmake nothing
gcc-8 -O0 -g -std=c99 -Wall -Wextra -Wshadow -pedantic –Werror    nothing.c   -o nothing
gcc-8: error: –Werror: No such file or directory
gmake: *** [<builtin>: nothing] Error 1

1 个答案:

答案 0 :(得分:3)

这里的问题是,在您的makefile中,破折号之前 Werror不是标准破折号,而是Unicode破折号(代码8211)

-pedantic –Werror

如果仔细观察,长度会略有不同。有时,文字处理程序或电子邮件客户端出于某种装饰性原因会切换破折号...

结果是选项解析器将其视为文件而不是选项,并尝试将其打开以进行编译。

当您知道以下内容时,此修补程序很明显:在CFLAGS中使用适当的破折号(在CPPFLAGS中使用破折号是可以的)

-pedantic -Werror