delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/01/20/17:57:27

X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: "Eric Lilja" <mindcooler AT gmail DOT com>
Subject: Re: Make things it's time to link when it should compile
Date: Fri, 20 Jan 2006 23:56:33 +0100
Lines: 114
Message-ID: <dqrpr3$uia$1@sea.gmane.org>
References: <dqrkej$abf$1 AT sea DOT gmane DOT org> <Pine DOT GSO DOT 4 DOT 63 DOT 0601201721250 DOT 13403 AT access1 DOT cims DOT nyu DOT edu>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019