Gcc and make not producing executable
Peter Boosten
peter at boosten.org
Tue Mar 18 23:38:55 PDT 2008
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
More information about the freebsd-questions
mailing list