Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Mar 2008 07:38:50 +0100
From:      Peter Boosten <peter@boosten.org>
To:        Eduardo Cerejo <ejcerejo@optonline.net>
Cc:        FreeBSD-questions@FreeBSD.org
Subject:   Re: Gcc and make not producing executable
Message-ID:  <47E0B4FA.1070605@boosten.org>
In-Reply-To: <20080318225936.9ef5af16.ejcerejo@optonline.net>
References:  <20080318225936.9ef5af16.ejcerejo@optonline.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Eduardo Cerejo wrote:
> Objective is to create a makefile which will create an executable named main.  The books has this code in the Makefile:
> 
> CC=gcc
> CFLAGS=-Wall
> main: main.o hello_fn.o
> 
> clean:
>         rm -f main main.o hello_fn.o
> 
> The book says this should create two object files named main.o and hello_fn.o plus an executable named main.  

gmake does the trick.

Otherwise your Makefile should look like this:

<begin Makefile>
main: main.o hello_fn.o
         gcc main.o hello_fn.o -o main

main.o: main.c
         gcc -c main.c

hello_fn.o: hello_fn.c
         gcc -c hello_fn.c


clean:
         rm -f main *.o

<end Makefile>

Or easier:

<begin Makefile>
CC=gcc

main: main.o hello_fn.o
         $(CC) main.o hello_fn.o -o main

.c.o:
         $(CC) $(CFLAGS) -c $<


clean:
         rm -f main *.o
<end Makefile>

Peter


-- 
http://www.boosten.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?47E0B4FA.1070605>