I’m working through exercise 2 in the C tutorial. My directory looks like this:
lucass-MacBook-Pro:learn_c_the_hard_way amodeo$ ls
ex1 ex1.c ex2.1.mak
rm -f ex1
The ex1 executable works fine. Also, the .mak is using tabs, not spaces.
When I go to -
I get -
make: *** No rule to make target `clean'. Stop.
What am I doing wrong? Thanks a ton for reading this far.
That’s not how it works. Delve into Makefile’s. The short: you have to create a Makefile. Every entry has to start with a tab. Starting with space will lead to weirdness.
The file is called literally Makefile.
That’s your problem for this issue.
EDIT: the file has no extension.
EDIT2: Not every entry has to start with a tab. Only the ones that are indented.
I was going to learn C next, just sounds like a pain in the back side.
This is not about C. It’s about make utilities. You can use that in every language that is machine compilable.
It has nothing to do with C other than that it supports building your program. It does so in a lot of other languages.
Managed languages like java and C# and interpreted languages often have different utilites with same goal. This is out of my area though.
What I am trying to say is this:
Do not let this stop you from learning any language. It has nothing to do with C.
On the other hand, if you think C is a PITA, it is. Still, I like it’s elegance and I am working hard to improve my attitude toward coding, using C. As the course shows, you need the attitude in every language.
Kind regards, Guus, lcthw student.
You just have to run it like this:
make -f ex.1.mak clean
If you don’t specify a makefile with -f then Make assumes you mean a file actually named
Yes! I was just coming here to mention this. Worked like a charm when I did it that way:
One other thing I did not see was the output as described in the example:
$ make -f ex1.mak clean
rm -f ex1
$ make ex1
cc ex1.c -o ex1
What I don’t see (and I don’t know if it matters - I guess it’s cause I’m using gcc?) are the flags in the output:
cc -Wall -g
I’m guessing there’s probably some switch / other flag / something that will show me the flags when I run make.
Yes, I believe you set CFLAGS to what you want for options.