简体   繁体   English

为什么gcc讨厌我简单的makefile?

[英]Why does gcc hate my simple makefile?

I have the following makefile that gcc doesn't like: 我有以下gcc不喜欢的makefile:

blah.exe:lex.yy.o
    gcc –o blah.exe lex.yy.o
lex.yy.o:lex.yy.c
    gcc  –c lex.yy.c
lex.yy.c:blah.lex
    flex blah.lex

If I delete everything except the orginal blah.lex file, then I get this error when I run make: 如果我删除除原始blah.lex文件之外的所有内容,那么当我运行make时出现此错误:

flex blah.lex
gcc  ûc lex.yy.c
gcc: ûc: No such file or directory
make: *** [lex.yy.o] Error 1

Now if i execute the following the commands in this order, it all works without errors and compiles. 现在,如果按此顺序执行以下命令,则所有操作都可以正常运行并进行编译。

flex blah.lex    
gcc  –c lex.yy.c
gcc –o blah.exe lex.yy.o

Following this, if I run make, it says: 在此之后,如果我运行make,它会说:

make: `blah.exe' is up to date.

This is normal response if the *.o and *.exe files exist. 如果存在* .o和* .exe文件,则这是正常响应。 But why wont 'make' work when these files need to be created. 但是,当需要创建这些文件时,为什么不能“工作”。

Note: I have put Tabs in the makefile. 注意:我已将选项卡放在makefile中。 flex is a tool that generates lex.yy.c based on the contents of blah.lex flex是一个基于blah.lex内容生成lex.yy.c的工具

If you copied the text directly from the Makefile , here is your problem: 如果您直接从Makefile复制文本,这是您的问题:

Instead of a simple dash (ASCII 45, Unicode U+002D) you have an en-dash (cp1252 0x96, Unicode U+2013) in the gcc -o ... and gcc -c ... lines. 您可以在gcc -o ...gcc -c ...行中使用简短的破折号(cp1252 0x96,Unicode U + 2013),而不是简单的破折号(ASCII 45,Unicode U + 002D)。 Replace them with simple dashes. 用简单的破折号替换它们。

To see whether you succeeded, use the following command: 要查看是否成功,请使用以下命令:

cat Makefile | tr -d '\r\n\t -~' | hexdump -C

This will extract all "weird" bytes from the Makefile and print them to you in a hexdump. 这将从Makefile中提取所有“怪异”字节,并在hexdump中将它们打印到您的身上。 Ideally the output of this command should be this: 理想情况下,此命令的输出应为:

00000000

In your case the output is probably: 在您的情况下,输出可能是:

00000000  ef bb bf e2 80 93 e2 80  93                       |.........|
00000009

This means that the file is UTF-8 encoded (the first three bytes tell you that), and there are two other UTF-8 characters in it: two times e2 80 93 , which is the UTF-8 encoding for U+2013, the en-dash. 这意味着文件是UTF-8编码的(前三个字节告诉你),其中还有另外两个UTF-8字符:两次e2 80 93 ,这是U + 2013的UTF-8编码, en-dash。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM