我试图跟随本课程(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发布于 2018-07-15 17:10:18
这里的问题是,在生成文件中,Werror之前的破折号不是一个标准的破折号,而是一个unicode破折号(代码8211)。
-pedantic –Werror如果你仔细观察,长度略有不同。有时文字处理器或电子邮件客户出于某种化妆的原因而更换破折号.
其结果是,选项解析器将其视为文件,而不是选项,并试图打开它来编译它。
当您知道:在CFLAGS中使用正确的破折号(在CPPFLAGS中这个破折号是ok的)时,修复是显而易见的:
-pedantic -Werrorhttps://stackoverflow.com/questions/51350416
复制相似问题