Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does gcc hate my simple makefile?

I have the following makefile that gcc doesn't 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 orginal blah.lex file, then I get this error when I run 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: `blah.exe' is up to date.

This is normal response if the *.o and *.exe files exist. But why wont 'make' work when these files need to be created.

Note: I have put Tabs in the makefile. flex is a tool that generates lex.yy.c based on the contents of blah.lex

like image 416
Matt G Avatar asked Oct 14 '11 22:10

Matt G


1 Answers

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 an en-dash (cp1252 0x96, Unicode U+2013) in the gcc -o ... and gcc -c ... lines. 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. 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.

like image 158
Roland Illig Avatar answered Sep 18 '22 20:09

Roland Illig