Mail Archives: cygwin/2006/01/20/17:57:27
Igor Peshansky wrote:
> On Fri, 20 Jan 2006, Eric Lilja wrote:
>
>> Hello, I'm having trouble with make for one simple program.
>> mikael AT mindcooler ~/coding/C/extract_acodes
>> $ ls -al
>> total 33K
>> drwxrwxrwx+ 2 mikael None 0 Jan 20 22:15 ./
>> drwxrwxrwx+ 22 mikael None 0 Dec 7 16:12 ../
>> -rwxrwxrwx 1 mikael None 264 Oct 14 13:54 Makefile*
>> -rw-r--r-- 1 mikael None 25K Jan 20 22:15 cygcheck.out
>> -rwxrwxrwx 1 mikael None 1.7K Oct 14 14:03 extract_acodes.c*
>>
>> mikael AT mindcooler ~/coding/C/extract_acodes
>> $ cat Makefile
>> CC = gcc
>> CFLAGS = -Wall -W -ansi -pedantic -g -O0 -c -o
>> LDFLAGS = -o $(EXEC)
>> EXEC = extract_acodes.exe
>> OBJECTS = extract_acodes.o
>>
>> all: $(OBJECTS)
>> $(CC) $^ $(LDFLAGS)
>>
>> %.o: %.c
>> $(CC) $(CLFAGS) $@ $<
>>
>> clean:
>> rm -f $(OBJECTS) $(EXEC) *~ *.stackdump
>>
>> mikael AT mindcooler ~/coding/C/extract_acodes
>> $ make
>> gcc extract_acodes.o extract_acodes.c
>> gcc: extract_acodes.o: No such file or directory
>> make: *** [extract_acodes.o] Error 1
>>
>> Compiling and linking the program manually works just fine:
>> $ gcc -Wall -W -ansi -pedantic -g -O0 -c extract_acodes.c
>>
>> mikael AT mindcooler ~/coding/C/extract_acodes
>> $ gcc extract_acodes.o -o extract_acodes.exe
>>
>> But when I try to use the make, it seems to think it's time for the
>> final linking stage...and it's just a problem with this particular
>> "project". Any ideas what's wrong? I'm sure the Makefile is the
>> culprit, but I can't see the error. cygcheck.out attached (I would
>> have used cygwin 1.5.19-4 but I couln't find it on my local mirrors
>> yet).
>
> Actually, make does exactly what you told it to do in line 11: invoke
> gcc with the empty value (of an uninitialized CLFAGS variable) after
> it, followed by the object file target, followed by the prerequisite
> source file. That's not a linking step. FWIW, you'd have the same
> exact trouble on Linux.
Ah, thanks for spotting that silly typo!¨
>
> For that reason, the "-o" option usually isn't part of CFLAGS. Aside
> from fixing the typo, I'd rewrite your Makefile as follows:
Actually, when I wrote the commands manually as shown in my first post I
wondered why I had -o as a part of CFLAGS. Must be remnant from the way my
Makefile used to look (a lot worse I can promise you that). Since I'm a
beginner, I don't want to use defaults just yet, but learn by specifying
things myself. If I remove -o from CFLAGS, I can rewrite the compilation
part like this
CFLAGS = -Wall -W -ansi -pedantic -g -O0 -c
%.o: %.c
$(CC) $(CFLAGS) $< #note: $< instead of $@ $<
right? It seems to work just fine..
>
> $ cat Makefile
> CC = gcc
> CFLAGS = -Wall -W -ansi -pedantic -g -O0
> LDFLAGS =
> EXEC = extract_acodes.exe
> OBJECTS = extract_acodes.o
>
> all: $(OBJECTS)
> $(CC) $(LDFLAGS) -o $(EXEC) $^ $(LDLIBS)
>
> %.o: %.c
> $(CC) $(CLFAGS) -c -o $@ $<
>
> clean:
> rm -f $(OBJECTS) $(EXEC) *~ *.stackdump
> $
>
> Considering that most of your actions directly reflect the implicit
> make rules anyway, I'd even go for
>
> $ cat Makefile
> CC = gcc
> CFLAGS = -Wall -W -ansi -pedantic -g -O0
> LDFLAGS =
> EXEC = extract_acodes.exe
> OBJECTS = extract_acodes.o
>
> all: $(EXEC)
>
> $(EXEC): $(OBJECTS)
>
> clean:
> rm -f $(OBJECTS) $(EXEC) *~ *.stackdump
> $
>
> HTH,
> Igor
/ E
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -