Why does gcc hate my simple makefile?

I have the following makefile that gcc does not like:

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 original blah.lex file, then I get this error when running 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 commands in this order, everything works without errors and compiles.

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

After that, if I run make, it says:

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

This is a normal answer if * .o and * .exe files exist. But why not β€œdo” the work when these files need to be created.

Note. I put the tabs in the make file. flex is a tool that generates lex.yy.c based on blah.lex content

+6
source share
1 answer

If you copied the text directly from the Makefile , here is your problem:

Instead of a simple dash (ASCII 45, Unicode U + 002D) you have en-dash (cp1252 0x96, Unicode U + 2013) in the gcc -o ... and gcc -c ... lines. Replace them with a simple dash.

To find out if you succeeded, use the following command:

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

This will extract all the β€œstrange” bytes from the Makefile and print them to you in hexdump. Ideally, the output of this command should be as follows:

 00000000 

In your case, there will probably be an output:

 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 this) and it has two other UTF-8 characters: two times e2 80 93 , which is the UTF-8 encoding for U + 2013, en-dash .

+10
source

Source: https://habr.com/ru/post/899338/


All Articles