i need help with my makefile. This is my first time dealing with one.I have ,ll.C and main.C, and one header file called ll.h
main.C has the header file ll.h included and some other libraries
ll.C has the header file also.
and when i compile it i get this error:

g++		 -c -g -Wall	 ll.C
g++		 -g -Wall	 -o mylink		 ll.o -L.		 -lm		
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [mylink] Error 1

and this is my makefile

###################################                                                                                                                    
#                                                                                                                                                      
###################################                                                                                                                    
CC = g++                                                                                             
CFLAGS = -g -Wall                                                       
LIB = -lm                                                                                                                          
LDFLAGS = -L.                                                                                                                         
PROG = mylink                                                                                                       
OBJ = main.o                            
OBJ = ll.o
SRC = main.C
SRC = ll.C
all : $(PROG)

$(PROG): $(OBJ)
        $(CC) -c $(CFLAGS) $(SRC)
        $(CC) $(CFLAGS) -o $(PROG) $(OBJ) $(LDFLAGS) $(LIB)


# cleanup                                                                                                                                              
clean:
        /bin/rm -f *.o $(PROG)

any help on how to fix this? and i do have a main function on main.C.

Edited 4 Years Ago by ruval002: n/a

In a makefile, the = is destructive assignment. You may be looking for somethign more along the lines of:

OBJ = main.o ll.o

or

OBJ = main.o
OBJ += ll.o

This is also apparent in the output of make where your compile line has only the ll.* file names listed.

You need specify each file's dependencies and the way they are built.

//11.o's recipee
11.o : 11.c 11.h
$(CC) $(CFLAGS) $< -o $@

//main.o's recipee
main.o : main.c
$(CC) $(CFLAGS) $< -o $@

//and finally the main program
all : main.o 11.o
$(CC) $? -o main_proj.exe

This article has been dead for over six months. Start a new discussion instead.